MCPcopy Index your code
hub / github.com/oshi/oshi / formatValue

Method formatValue

oshi-core/src/main/java/oshi/util/FormatUtil.java:161–177  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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.

Callers 3

printFileSystemMethod · 0.95
formatBytesDecimalMethod · 0.95
formatHertzMethod · 0.95

Calls 1

formatUnitsMethod · 0.95

Tested by 1

printFileSystemMethod · 0.76