sdf
This commit is contained in:
parent
a49427e88b
commit
0124fc6ace
|
|
@ -1,3 +1,5 @@
|
|||
module proj1
|
||||
|
||||
go 1.24.5
|
||||
|
||||
require go.uber.org/zap v1.27.1
|
||||
|
|
|
|||
2
go_book/proj1/go.sum
Normal file
2
go_book/proj1/go.sum
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
go.uber.org/zap v1.27.1 h1:08RqriUEv8+ArZRYSTXy1LeBScaMpVSTBhCeaZYfMYc=
|
||||
go.uber.org/zap v1.27.1/go.mod h1:GB2qFLM7cTU87MWRP2mPIjqfIDnGu+VIO4V/SdhGo2E=
|
||||
|
|
@ -2,13 +2,29 @@ package main
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
// "strings"
|
||||
"strconv"
|
||||
"go.uber.org/zap/buffer"
|
||||
)
|
||||
|
||||
func addCommas(n int) string {
|
||||
str := strconv.Itoa(n)
|
||||
|
||||
// Add commas from right to left
|
||||
var result buffer.Buffer
|
||||
for i := range str {
|
||||
if i > 0 && (len(str)-i)%3 == 0 {
|
||||
fmt.Fprint(&result,",")
|
||||
}
|
||||
result.WriteByte(str[i])
|
||||
}
|
||||
|
||||
return result.String()
|
||||
}
|
||||
|
||||
func main() {
|
||||
// var sum string
|
||||
for key,val := range os.Args[:]{
|
||||
fmt.Println("num is",key,"value is", val)
|
||||
numbers := []int{12345, 1234567, 987654321, 12345, 123, 0}
|
||||
|
||||
for _, num := range numbers {
|
||||
fmt.Printf("%d -> %s\n", num, addCommas(num))
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user