Skip to content

Commit 1a58716

Browse files
committed
UnitUtils: expose formatting logic
Move the numeric formatting to a utility method.
1 parent b66ff31 commit 1a58716

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

src/main/java/org/scijava/util/UnitUtils.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,14 @@ public static String getAbbreviatedByteLabel(final double totBytes) {
6666
// compute value from unit
6767
final double value = totBytes / Math.pow(1024.0, pow);
6868

69-
// format result with 0 decimal places for bytes, or 1 for larger values
70-
final String format = pow == 0 ? "%.0f%s" : "%.1f%s";
69+
final String format = format(pow);
7170
return String.format(format, value, BYTE_UNITS[pow]);
7271
}
7372

73+
/**
74+
* @return Format result with 0 decimal places for bytes, or 1 for larger values
75+
*/
76+
public static String format(final double power) {
77+
return power == 0 ? "%.0f%s" : "%.1f%s";
78+
}
7479
}

0 commit comments

Comments
 (0)