(f float64)
| 134 | var suffixes = [...]string{"", "k", "M", "G", "T"} |
| 135 | |
| 136 | func niceFloat(f float64) string { |
| 137 | idx := 0 |
| 138 | for f >= 1000 { |
| 139 | f /= 1000 |
| 140 | idx++ |
| 141 | } |
| 142 | if idx >= len(suffixes) { |
| 143 | return fmt.Sprintf("%f", f) |
| 144 | } |
| 145 | suf := suffixes[idx] |
| 146 | switch { |
| 147 | case f >= 100: |
| 148 | return fmt.Sprintf("%.1f%s", f, suf) |
| 149 | case f >= 10: |
| 150 | return fmt.Sprintf("%.2f%s", f, suf) |
| 151 | default: |
| 152 | return fmt.Sprintf("%.3f%s", f, suf) |
| 153 | } |
| 154 | } |