我试图将一些数字格式化为货币,用逗号和2位小数.我发现逗号有"github.com/dustin/go-humanize"但它不允许指定小数位数.fmt.Sprintf将执行货币和小数格式,但不会使用逗号.
for _, fl := range []float64{123456.789, 123456.0, 123456.0100} {
log.Println(humanize.Commaf(fl))
}
Run Code Online (Sandbox Code Playgroud)
结果:
123,456.789
123,456
123,456.01
Run Code Online (Sandbox Code Playgroud)
我期待:
$123,456.79
$123,456.00
$123,456.01
Run Code Online (Sandbox Code Playgroud)