Преглед на файлове

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
Benjamin Sago преди 4 години
родител
ревизия
2aaead1721
променени са 1 файла, в които са добавени 8 реда и са изтрити 8 реда
  1. 8 8
      src/output/render/size.rs

+ 8 - 8
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),