27 lines
421 B
Go
27 lines
421 B
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"strings"
|
|
)
|
|
|
|
// fmtCount formats a count with a space as the thousands separator.
|
|
func fmtCount(n int64) string {
|
|
s := fmt.Sprintf("%d", n)
|
|
if len(s) <= 3 {
|
|
return s
|
|
}
|
|
var b strings.Builder
|
|
start := len(s) % 3
|
|
if start > 0 {
|
|
b.WriteString(s[:start])
|
|
}
|
|
for i := start; i < len(s); i += 3 {
|
|
if i > 0 {
|
|
b.WriteByte(' ')
|
|
}
|
|
b.WriteString(s[i : i+3])
|
|
}
|
|
return b.String()
|
|
}
|