mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-30 04:27:45 +00:00
Merge pull request #3530 from cakebaker/fix_size_header_rounding
df: fix incorrect rounding of size header
This commit is contained in:
commit
9fb19c12a3
1 changed files with 2 additions and 1 deletions
|
@ -99,7 +99,7 @@ fn to_magnitude_and_suffix_not_powers_of_1024(n: u128) -> Result<String, ()> {
|
||||||
|
|
||||||
if rem % (SI_BASES[i] / 10) == 0 {
|
if rem % (SI_BASES[i] / 10) == 0 {
|
||||||
Ok(format!("{}.{}{}", quot, tenths_place, suffix))
|
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))
|
Ok(format!("{}{}", quot + 1, suffix))
|
||||||
} else {
|
} else {
|
||||||
Ok(format!("{}.{}{}", quot, tenths_place + 1, suffix))
|
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(1001).unwrap(), "1.1kB");
|
||||||
assert_eq!(to_magnitude_and_suffix(1023).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(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_000).unwrap(), "999kB");
|
||||||
|
|
||||||
assert_eq!(to_magnitude_and_suffix(999_001).unwrap(), "1MB");
|
assert_eq!(to_magnitude_and_suffix(999_001).unwrap(), "1MB");
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue