MCPcopy Create free account
hub / github.com/github/gh-aw / FormatNumber

Function FormatNumber

pkg/console/render.go:674–714  ·  view source on GitHub ↗

FormatNumber formats large numbers in a human-readable way (e.g., "1k", "1.2k", "1.12M")

(n int)

Source from the content-addressed store, hash-verified

672
673// FormatNumber formats large numbers in a human-readable way (e.g., "1k", "1.2k", "1.12M")
674func FormatNumber(n int) string {
675 if n == 0 {
676 return "0"
677 }
678
679 f := float64(n)
680
681 if f < 1000 {
682 return strconv.Itoa(n)
683 } else if f < 1000000 {
684 // Format as thousands (k)
685 k := f / 1000
686 if k >= 100 {
687 return fmt.Sprintf("%.0fk", k)
688 } else if k >= 10 {
689 return fmt.Sprintf("%.1fk", k)
690 } else {
691 return fmt.Sprintf("%.2fk", k)
692 }
693 } else if f < 1000000000 {
694 // Format as millions (M)
695 m := f / 1000000
696 if m >= 100 {
697 return fmt.Sprintf("%.0fM", m)
698 } else if m >= 10 {
699 return fmt.Sprintf("%.1fM", m)
700 } else {
701 return fmt.Sprintf("%.2fM", m)
702 }
703 } else {
704 // Format as billions (B)
705 b := f / 1000000000
706 if b >= 100 {
707 return fmt.Sprintf("%.0fB", b)
708 } else if b >= 10 {
709 return fmt.Sprintf("%.1fB", b)
710 } else {
711 return fmt.Sprintf("%.2fB", b)
712 }
713 }
714}
715
716// FormatTokens formats a token count as a compact human-readable string.
717// Zero is rendered as "-"; values below 1000 are rendered as plain integers;

Callers 6

generateFindingsFunction · 0.92
TestFormatNumberFunction · 0.92
renderConsoleFunction · 0.92
TestFormatNumberFunction · 0.85
applyNumberFormatFunction · 0.85

Calls

no outgoing calls

Tested by 3

TestFormatNumberFunction · 0.74
TestFormatNumberFunction · 0.68