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 2525package com .oracle .svm .core .util ;
2626
2727public 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+ */
2933 private static final int MAX_WIDTH = 9 ;
34+
3035 public static final String RIGHT_ALIGNED_FORMAT = "%" + MAX_WIDTH + "s" ;
3136
3237 private enum Unit {
@@ -61,9 +66,6 @@ public static String bytesToHumanGB(long bytes) {
6166 }
6267
6368 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 ());
6870 }
6971}
You can’t perform that action at this time.
0 commit comments