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

Function humanCompact

internal/app/stats.go:187–201  ·  view source on GitHub ↗

humanCompact formats large numbers with B/M/K suffix for compact display. ≥1B → "X.XXB"; ≥1M → "X.XXM"; ≥1K → "XK" or "X.XK"; else plain integer.

(n int64)

Source from the content-addressed store, hash-verified

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.
187func humanCompact(n int64) string {
188 switch {
189 case n >= 1_000_000_000:
190 return fmt.Sprintf("%.2fB", float64(n)/1e9)
191 case n >= 1_000_000:
192 return fmt.Sprintf("%.2fM", float64(n)/1e6)
193 case n >= 1_000:
194 if n%1000 == 0 {
195 return fmt.Sprintf("%dK", n/1000)
196 }
197 return fmt.Sprintf("%.1fK", float64(n)/1e3)
198 default:
199 return fmt.Sprintf("%d", n)
200 }
201}
202
203var sparkRunes = []rune("▁▂▃▄▅▆▇█")
204

Callers 3

renderCardHTMLFunction · 0.85
renderCardPNGFunction · 0.85
TestHumanCompactFunction · 0.85

Calls

no outgoing calls

Tested by 1

TestHumanCompactFunction · 0.68