Skip to content

Commit

Permalink
Use thousand separators again and fix alignement when it’s not ASCII
Browse files Browse the repository at this point in the history
  • Loading branch information
ariasuni committed Apr 6, 2021
1 parent 505808f commit 7a4cde7
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions src/output/render/size.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down

0 comments on commit 7a4cde7

Please sign in to comment.