MCPcopy Create free account
hub / github.com/Facets-cloud/flow / humanInt

Function humanInt

internal/app/stats.go:162–183  ·  view source on GitHub ↗

humanInt formats n with thousands separators (e.g. 1041234 → "1,041,234"). Pure Go, no third-party deps.

(n int64)

Source from the content-addressed store, hash-verified

160// humanInt formats n with thousands separators (e.g. 1041234 → "1,041,234").
161// Pure Go, no third-party deps.
162func humanInt(n int64) string {
163 if n < 0 {
164 return "-" + humanInt(-n)
165 }
166 s := fmt.Sprintf("%d", n)
167 // Insert commas every 3 digits from the right.
168 if len(s) <= 3 {
169 return s
170 }
171 var b strings.Builder
172 rem := len(s) % 3
173 if rem > 0 {
174 b.WriteString(s[:rem])
175 }
176 for i := rem; i < len(s); i += 3 {
177 if i > 0 {
178 b.WriteByte(',')
179 }
180 b.WriteString(s[i : i+3])
181 }
182 return b.String()
183}
184
185// humanCompact formats large numbers with B/M/K suffix for compact display.
186// ≥1B → "X.XXB"; ≥1M → "X.XXM"; ≥1K → "XK" or "X.XK"; else plain integer.

Callers 4

renderCardHTMLFunction · 0.85
renderCardPNGFunction · 0.85
TestHumanIntFunction · 0.85
renderReportFunction · 0.85

Calls 1

StringMethod · 0.80

Tested by 1

TestHumanIntFunction · 0.68