|
@@ -13,12 +13,20 @@ const (
|
|
|
|
|
|
func HumanNumber(b uint64) string {
|
|
func HumanNumber(b uint64) string {
|
|
switch {
|
|
switch {
|
|
- case b > Billion:
|
|
|
|
- return fmt.Sprintf("%.0fB", math.Round(float64(b)/Billion))
|
|
|
|
- case b > Million:
|
|
|
|
- return fmt.Sprintf("%.0fM", math.Round(float64(b)/Million))
|
|
|
|
- case b > Thousand:
|
|
|
|
- return fmt.Sprintf("%.0fK", math.Round(float64(b)/Thousand))
|
|
|
|
|
|
+ case b >= Billion:
|
|
|
|
+ number := float64(b) / Billion
|
|
|
|
+ if number == math.Floor(number) {
|
|
|
|
+ return fmt.Sprintf("%.0fB", number) // no decimals if whole number
|
|
|
|
+ }
|
|
|
|
+ return fmt.Sprintf("%.1fB", number) // one decimal if not a whole number
|
|
|
|
+ case b >= Million:
|
|
|
|
+ number := float64(b) / Million
|
|
|
|
+ if number == math.Floor(number) {
|
|
|
|
+ return fmt.Sprintf("%.0fM", number) // no decimals if whole number
|
|
|
|
+ }
|
|
|
|
+ return fmt.Sprintf("%.2fM", number) // two decimals if not a whole number
|
|
|
|
+ case b >= Thousand:
|
|
|
|
+ return fmt.Sprintf("%.0fK", float64(b)/Thousand)
|
|
default:
|
|
default:
|
|
return fmt.Sprintf("%d", b)
|
|
return fmt.Sprintf("%d", b)
|
|
}
|
|
}
|