display one digit after dot
Vladimir Bauer
9 years ago
| 51 | 51 | func formatBytes(i int) (result string) { |
| 52 | 52 | switch { |
| 53 | 53 | case i > bytesInTiB: |
| 54 | result = fmt.Sprintf("%.02fTiB", float64(i)/bytesInTiB) | |
| 54 | result = fmt.Sprintf("%.1fTiB", float64(i)/bytesInTiB) | |
| 55 | 55 | case i > bytesInGiB: |
| 56 | result = fmt.Sprintf("%.02fGiB", float64(i)/bytesInGiB) | |
| 56 | result = fmt.Sprintf("%.1fGiB", float64(i)/bytesInGiB) | |
| 57 | 57 | case i > bytesInMiB: |
| 58 | result = fmt.Sprintf("%.02fMiB", float64(i)/bytesInMiB) | |
| 58 | result = fmt.Sprintf("%.1fMiB", float64(i)/bytesInMiB) | |
| 59 | 59 | case i > bytesInKiB: |
| 60 | result = fmt.Sprintf("%.02fKiB", float64(i)/bytesInKiB) | |
| 60 | result = fmt.Sprintf("%.1fKiB", float64(i)/bytesInKiB) | |
| 61 | 61 | default: |
| 62 | 62 | result = fmt.Sprintf("%db", i) |
| 63 | 63 | } |