This commit is contained in:
a.pivkin 2025-12-25 21:11:11 +03:00
parent a49427e88b
commit 0124fc6ace
3 changed files with 26 additions and 6 deletions

View File

@ -1,3 +1,5 @@
module proj1 module proj1
go 1.24.5 go 1.24.5
require go.uber.org/zap v1.27.1

2
go_book/proj1/go.sum Normal file
View 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=

View File

@ -2,13 +2,29 @@ package main
import ( import (
"fmt" "fmt"
"os" "strconv"
// "strings" "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() { func main() {
// var sum string numbers := []int{12345, 1234567, 987654321, 12345, 123, 0}
for key,val := range os.Args[:]{
fmt.Println("num is",key,"value is", val) for _, num := range numbers {
} fmt.Printf("%d -> %s\n", num, addCommas(num))
}
} }