From 576aafb00f5e8cfd9d294578412b594734f84820 Mon Sep 17 00:00:00 2001 From: Daniel Hofstetter Date: Sun, 15 May 2022 16:25:17 +0200 Subject: [PATCH] df: fix incorrect rounding of size header --- src/uu/df/src/blocks.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/uu/df/src/blocks.rs b/src/uu/df/src/blocks.rs index 594c18acc..88190b5c1 100644 --- a/src/uu/df/src/blocks.rs +++ b/src/uu/df/src/blocks.rs @@ -99,7 +99,7 @@ fn to_magnitude_and_suffix_not_powers_of_1024(n: u128) -> Result { if rem % (SI_BASES[i] / 10) == 0 { Ok(format!("{}.{}{}", quot, tenths_place, suffix)) - } else if tenths_place + 1 == 10 { + } else if tenths_place + 1 == 10 || quot >= 10 { Ok(format!("{}{}", quot + 1, suffix)) } else { Ok(format!("{}.{}{}", quot, tenths_place + 1, suffix)) @@ -245,6 +245,7 @@ mod tests { assert_eq!(to_magnitude_and_suffix(1001).unwrap(), "1.1kB"); assert_eq!(to_magnitude_and_suffix(1023).unwrap(), "1.1kB"); assert_eq!(to_magnitude_and_suffix(1025).unwrap(), "1.1kB"); + assert_eq!(to_magnitude_and_suffix(10_001).unwrap(), "11kB"); assert_eq!(to_magnitude_and_suffix(999_000).unwrap(), "999kB"); assert_eq!(to_magnitude_and_suffix(999_001).unwrap(), "1MB");