File tree Expand file tree Collapse file tree 1 file changed +7
-5
lines changed
substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/util Expand file tree Collapse file tree 1 file changed +7
-5
lines changed Original file line number Diff line number Diff line change 25
25
package com .oracle .svm .core .util ;
26
26
27
27
public class ByteFormattingUtil {
28
- // "123.12KiB".length() = 9, holds as long as it's not >= 1000GiB
28
+ /**
29
+ * {@code "123.12KiB".length() = 9} almost always holds as long as the value is not >= 1000GiB
30
+ * and {@link String#format} floating point rounding does not bump the whole part to 4 digits
31
+ * (e.g. {@code String.format("%.2f", 999.995D) == "1000.00"}).
32
+ */
29
33
private static final int MAX_WIDTH = 9 ;
34
+
30
35
public static final String RIGHT_ALIGNED_FORMAT = "%" + MAX_WIDTH + "s" ;
31
36
32
37
private enum Unit {
@@ -61,9 +66,6 @@ public static String bytesToHumanGB(long bytes) {
61
66
}
62
67
63
68
private static String toHuman (long value , Unit unit ) {
64
- long scaled = value / unit .value ;
65
- String string = "%.2f%s" .formatted ((double ) scaled , unit .toString ());
66
- assert string .length () <= MAX_WIDTH || value >= 1000L * Unit .GiB .value : value ;
67
- return string ;
69
+ return "%.2f%s" .formatted ((double ) value / (double ) unit .value , unit .toString ());
68
70
}
69
71
}
You can’t perform that action at this time.
0 commit comments