FormatBytesUnit outputs the given number of bytes "s" as a quantity of the given units "u" to the nearest half within .01.
(s, u uint64)
| 117 | // FormatBytesUnit outputs the given number of bytes "s" as a quantity of the |
| 118 | // given units "u" to the nearest half within .01. |
| 119 | func FormatBytesUnit(s, u uint64) string { |
| 120 | var rounded float64 |
| 121 | if s < 10 { |
| 122 | rounded = float64(s) |
| 123 | } else { |
| 124 | rounded = math.Floor(float64(s)/float64(u)*10+.5) / 10 |
| 125 | } |
| 126 | |
| 127 | format := "%.0f" |
| 128 | if rounded < 10 && u > 1 { |
| 129 | format = "%.1f" |
| 130 | } |
| 131 | |
| 132 | return fmt.Sprintf(format, rounded) |
| 133 | } |
| 134 | |
| 135 | // FormatByteRate outputs the given rate of transfer "r" as the quotient of "s" |
| 136 | // (the number of bytes transferred) over "d" (the duration of time that those |
no outgoing calls