Skip to content

Commit 66b58ee

Browse files
fmeumcopybara-github
authored andcommitted
Always emit trailing zero in human-readable download progress
The human-readable download progress (e.g. "8.2 MiB") typically changes rapidly and, especially in the common "MiB" range, is very "jumpy" if the trailing digit is only shown if it's non-zero. Closes bazelbuild#16950. PiperOrigin-RevId: 493849764 Change-Id: I115923d572b35e304280499746d28a24df83c3f3
1 parent 86dee6d commit 66b58ee

File tree

2 files changed

+7
-7
lines changed
  • src
    • main/java/com/google/devtools/build/lib/remote/util
    • test/java/com/google/devtools/build/lib/remote/util

2 files changed

+7
-7
lines changed

src/main/java/com/google/devtools/build/lib/remote/util/Utils.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -542,9 +542,9 @@ public static <V> V refreshIfUnauthenticated(
542542
}
543543

544544
private static final ImmutableList<String> UNITS = ImmutableList.of("KiB", "MiB", "GiB", "TiB");
545-
// Format as single digit decimal number, but skipping the trailing .0.
545+
// Format as single digit decimal number.
546546
private static final DecimalFormat BYTE_COUNT_FORMAT =
547-
new DecimalFormat("0.#", new DecimalFormatSymbols(Locale.US));
547+
new DecimalFormat("0.0", new DecimalFormatSymbols(Locale.US));
548548

549549
/**
550550
* Converts the number of bytes to a human readable string, e.g. 1024 -> 1 KiB.

src/test/java/com/google/devtools/build/lib/remote/util/UtilsTest.java

+5-5
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,14 @@ public class UtilsTest {
2626
@Test
2727
public void bytesCountToDisplayString_works() {
2828
assertThat(bytesCountToDisplayString(1000)).isEqualTo("1000 B");
29-
assertThat(bytesCountToDisplayString(1 << 10)).isEqualTo("1 KiB");
29+
assertThat(bytesCountToDisplayString(1 << 10)).isEqualTo("1.0 KiB");
3030
assertThat(bytesCountToDisplayString((1 << 10) + (1 << 10) / 10)).isEqualTo("1.1 KiB");
31-
assertThat(bytesCountToDisplayString(1 << 20)).isEqualTo("1 MiB");
31+
assertThat(bytesCountToDisplayString(1 << 20)).isEqualTo("1.0 MiB");
3232
assertThat(bytesCountToDisplayString((1 << 20) + (1 << 20) / 10)).isEqualTo("1.1 MiB");
33-
assertThat(bytesCountToDisplayString(1 << 30)).isEqualTo("1 GiB");
33+
assertThat(bytesCountToDisplayString(1 << 30)).isEqualTo("1.0 GiB");
3434
assertThat(bytesCountToDisplayString((1 << 30) + (1 << 30) / 10)).isEqualTo("1.1 GiB");
35-
assertThat(bytesCountToDisplayString(1L << 40)).isEqualTo("1 TiB");
35+
assertThat(bytesCountToDisplayString(1L << 40)).isEqualTo("1.0 TiB");
3636
assertThat(bytesCountToDisplayString((1L << 40) + (1L << 40) / 10)).isEqualTo("1.1 TiB");
37-
assertThat(bytesCountToDisplayString(1L << 50)).isEqualTo("1024 TiB");
37+
assertThat(bytesCountToDisplayString(1L << 50)).isEqualTo("1024.0 TiB");
3838
}
3939
}

0 commit comments

Comments
 (0)