1
0
Fork 0
mirror of https://github.com/Luzifer/badge-gen.git synced 2024-11-08 13:20:02 +00:00
badge-gen/metric.go

18 lines
360 B
Go
Raw Permalink Normal View History

2016-07-06 23:25:09 +00:00
package main
import (
"fmt"
"math"
)
func metricFormat(in int64) string {
siUnits := []string{"k", "M", "G", "T", "P", "E"}
for i := len(siUnits) - 1; i >= 0; i-- {
p := int64(math.Pow(1000, float64(i+1))) //nolint:gomnd // Makes no sense to extract
2016-07-06 23:25:09 +00:00
if in >= p {
return fmt.Sprintf("%d%s", in/p, siUnits[i])
}
}
return fmt.Sprintf("%d", in)
}