improve display of multiple base units

Signed-off-by: eternal-flame-AD <yume@yumechi.jp>
This commit is contained in:
ゆめ 2024-07-29 12:16:34 -05:00
parent 8bffee834c
commit 34f62ae693
No known key found for this signature in database

View file

@ -180,7 +180,11 @@ impl Display for UnitCombo {
exponents.sort_by(|a, b| b.exponent.cmp(&a.exponent)); exponents.sort_by(|a, b| b.exponent.cmp(&a.exponent));
for exponent in exponents.iter() { for exponent in exponents.iter() {
if exponent.exponent == 1 { if exponent.exponent == 1 {
write!(f, "{}", exponent.unit.symbol)?; if exponents.len() > 1 {
write!(f, "({})", exponent.unit.symbol)?;
} else {
write!(f, "{}", exponent.unit.symbol)?;
}
} else { } else {
write!(f, "({}^{})", exponent.unit.symbol, exponent.exponent)?; write!(f, "({}^{})", exponent.unit.symbol, exponent.exponent)?;
} }