From 7a4cde75ebeb166edf4f026ef485f1c54b7375b8 Mon Sep 17 00:00:00 2001 From: ariasuni Date: Tue, 6 Apr 2021 15:18:37 +0200 Subject: [PATCH] =?UTF-8?q?Use=20thousand=20separators=20again=20and=20fix?= =?UTF-8?q?=20alignement=20when=20it=E2=80=99s=20not=20ASCII?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/output/render/size.rs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/output/render/size.rs b/src/output/render/size.rs index 7f1acb7..94f751b 100644 --- a/src/output/render/size.rs +++ b/src/output/render/size.rs @@ -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),