Merge pull request #830 from ariasuni/fix-alignement-with-non-ascii-thousands-separator

Use thousand separators again and fix alignement when it’s not ASCII
This commit is contained in:
Benjamin Sago 2021-04-08 23:33:54 +01:00 committed by GitHub
commit 2aaead1721
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -36,20 +36,20 @@ impl f::Size {
};
let (prefix, n) = match result {
NumberPrefix::Standalone(b) => return TextCell::paint(colours.size(None), b.to_string()),
NumberPrefix::Standalone(b) => return TextCell::paint(colours.size(None), numerics.format_int(b)),
NumberPrefix::Prefixed(p, n) => (p, n),
};
let symbol = prefix.symbol();
let decimal_to_diplay = if n < 10_f64 { 1 } else { 0 };
let number = numerics.format_float(n, decimal_to_diplay);
let number = if n < 10_f64 {
numerics.format_float(n, 1)
} else {
numerics.format_int(n.round() as isize)
};
// 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());
TextCell {
width,
// symbol is guaranteed to be ASCII since unit prefixes are hardcoded.
width: DisplayWidth::from(&*number) + symbol.len(),
contents: vec![
colours.size(Some(prefix)).paint(number),
colours.unit(Some(prefix)).paint(symbol),