1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-27 19:17:43 +00:00

Fix #7221: Unit::SI uses lowercase k for kilos

Other units remain untouched and use uppercase `K`, as well as all other suffixes

Signed-off-by: Alex Snaps <alex@wcgw.dev>
This commit is contained in:
Alex Snaps 2025-02-18 15:30:26 -05:00
parent bc995283c4
commit 1250195bce
No known key found for this signature in database
GPG key ID: D95FB9EFA518E173
2 changed files with 15 additions and 14 deletions

View file

@ -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)),
})
}

View file

@ -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"),