Format arbitrary units into a string to a rounded string representation. @param value The value @param unit Units to append metric prefix to @return Rounded string representation of the value with metric prefix to extension
(long value, String unit)
| 159 | * extension |
| 160 | */ |
| 161 | public static String formatValue(long value, String unit) { |
| 162 | if (value < KILO) { |
| 163 | return String.format("%d %s", value, unit).trim(); |
| 164 | } else if (value < MEGA) { // K |
| 165 | return formatUnits(value, KILO, "K" + unit); |
| 166 | } else if (value < GIGA) { // M |
| 167 | return formatUnits(value, MEGA, "M" + unit); |
| 168 | } else if (value < TERA) { // G |
| 169 | return formatUnits(value, GIGA, "G" + unit); |
| 170 | } else if (value < PETA) { // T |
| 171 | return formatUnits(value, TERA, "T" + unit); |
| 172 | } else if (value < EXA) { // P |
| 173 | return formatUnits(value, PETA, "P" + unit); |
| 174 | } else { // E |
| 175 | return formatUnits(value, EXA, "E" + unit); |
| 176 | } |
| 177 | } |
| 178 | |
| 179 | /** |
| 180 | * Formats an elapsed time in seconds as days, hh:mm:ss. |