Merge pull request #822 from ariasuni/fix-exa-rounding

Fix a rounding error in human readable filesizes
This commit is contained in:
Benjamin Sago 2021-03-30 14:50:29 +01:00 committed by GitHub
commit f27fb2ab7a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -41,9 +41,9 @@ impl f::Size {
};
let symbol = prefix.symbol();
let number = if n < 10_f64 { numerics.format_float(n, 1) }
else { numerics.format_int(n as isize) };
let decimal_to_diplay = if n < 10_f64 { 1 } else { 0 };
let number = numerics.format_float(n, decimal_to_diplay);
// The numbers and symbols are guaranteed to be written in ASCII, so
// we can skip the display width calculation.
let width = DisplayWidth::from(number.len() + symbol.len());