package steam import ( "fmt" "math" ) func formatBytes(b int64) string { if b < 1024 { return fmt.Sprintf("%d b", b) } s := "" pfxs := "kmgt" for i := 0; i < len(pfxs); i++ { pow := math.Pow(float64(1024), float64(i+1)) // This one is too big, return the previous string if b < int64(pow) { return s } s = fmt.Sprintf("%.2f %cb", float64(b)/(pow), pfxs[i]) } return s }