fusenapi/utils/format/number.go
laodaming 01b78a099a fix
2023-09-26 18:35:27 +08:00

26 lines
441 B
Go

package format
import (
"fmt"
"strings"
)
// 数字变成带千分位的字符串
func NumToStringWithThousandthPercentile(number int64) string {
s := fmt.Sprintf("%d", number)
l := len(s)
if l <= 3 {
return s
}
r := l % 3 //前面第几位开始加入千分位
b := strings.Builder{}
for i := 0; i < l; i++ {
b.WriteString(string(s[i]))
if i+1 == r && i != l-1 {
b.WriteString(",")
r += 3
}
}
return b.String()
}