Skip to content

Commit

Permalink
Fix #7221: Unit::SI uses lowercase k for kilos
Browse files Browse the repository at this point in the history
Other units remain untouched and use uppercase `K`, as well as all other suffixes

Signed-off-by: Alex Snaps <[email protected]>
  • Loading branch information
alexsnaps committed Feb 18, 2025
1 parent bc99528 commit 1250195
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 14 deletions.
6 changes: 3 additions & 3 deletions src/uu/numfmt/src/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -281,12 +281,12 @@ fn transform_to(
format!(
"{:.precision$}{}",
i2,
DisplayableSuffix(s),
DisplayableSuffix(s, opts.to),
precision = precision
)
}
Some(s) if i2.abs() < 10.0 => format!("{:.1}{}", i2, DisplayableSuffix(s)),
Some(s) => format!("{:.0}{}", i2, DisplayableSuffix(s)),
Some(s) if i2.abs() < 10.0 => format!("{:.1}{}", i2, DisplayableSuffix(s, opts.to)),
Some(s) => format!("{:.0}{}", i2, DisplayableSuffix(s, opts.to)),
})
}

Expand Down
23 changes: 12 additions & 11 deletions src/uu/numfmt/src/units.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,20 +45,21 @@ pub enum RawSuffix {

pub type Suffix = (RawSuffix, WithI);

pub struct DisplayableSuffix(pub Suffix);
pub struct DisplayableSuffix(pub Suffix, pub Unit);

impl fmt::Display for DisplayableSuffix {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
let Self((ref raw_suffix, ref with_i)) = *self;
match raw_suffix {
RawSuffix::K => write!(f, "K"),
RawSuffix::M => write!(f, "M"),
RawSuffix::G => write!(f, "G"),
RawSuffix::T => write!(f, "T"),
RawSuffix::P => write!(f, "P"),
RawSuffix::E => write!(f, "E"),
RawSuffix::Z => write!(f, "Z"),
RawSuffix::Y => write!(f, "Y"),
let Self((ref raw_suffix, ref with_i), unit) = *self;
match (raw_suffix, unit) {
(RawSuffix::K, Unit::Si) => write!(f, "k"),
(RawSuffix::K, _) => write!(f, "K"),
(RawSuffix::M, _) => write!(f, "M"),
(RawSuffix::G, _) => write!(f, "G"),
(RawSuffix::T, _) => write!(f, "T"),
(RawSuffix::P, _) => write!(f, "P"),
(RawSuffix::E, _) => write!(f, "E"),
(RawSuffix::Z, _) => write!(f, "Z"),
(RawSuffix::Y, _) => write!(f, "Y"),
}
.and_then(|()| match with_i {
true => write!(f, "i"),
Expand Down

0 comments on commit 1250195

Please sign in to comment.