在Go中打印一个带有(逗号)千位分隔符的数字
package main import ( "fmt" "golang.org/x/text/language" "golang.org/x/text/message" ) func main() { number := 1_000_000.23456 p := message.NewPrinter(language.English) withCommaThousandSep := p.Sprintf("%f", number) fmt.Println(withCommaThousandSep) }
1,000,000.234560
package main import ( "fmt" "golang.org/x/text/language" "golang.org/x/text/message" ) func main() { number := 1_000_000.23456 langs := []language.Tag{ language.German, language.Ukrainian, language.Chinese, language.Arabic, language.French, } for _, l := range langs { p := message.NewPrinter(l) withCommaThousandSep := p.Sprintf("%s %f", l, number) fmt.Println(withCommaThousandSep) } }
de 1.000.000,234560 uk 1 000 000,234560 zh 1,000,000.234560 ar ١٬٠٠٠٬٠٠٠٫٢٣٤٥٦٠ fr 1 000 000,234560
评论:
2022-10-05 23:43