meas: render the SI prefix
This commit is contained in:
@@ -74,13 +74,12 @@ impl Measurement {
|
||||
|
||||
pub fn str_value(&self) -> String {
|
||||
use MeasurementValue::*;
|
||||
let val = match self.value {
|
||||
Field(v) => v.to_string(),
|
||||
Float(f) => f.to_string(),
|
||||
Int(u) => u.to_string(),
|
||||
Dim(v) => format!("{}x{}x{}", v.x(), v.y(), v.z()),
|
||||
};
|
||||
format!("{}{}", val, self.unit)
|
||||
match self.value {
|
||||
Field(v) => format!("{}{}", v, self.unit),
|
||||
Float(f) => SiScale::format_short(f, &self.unit),
|
||||
Int(u) => format!("{}{}", u, self.unit),
|
||||
Dim(v) => format!("{}x{}x{}{}", v.x(), v.y(), v.z(), self.unit),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -161,7 +160,7 @@ impl SiScale {
|
||||
/// e.g. `format_short(1234, "A") -> "1.23 kA"
|
||||
fn format_short(v: f32, unit: &str) -> String {
|
||||
let si = SiScale::for_value(v);
|
||||
let scaled = si.scale() * v;
|
||||
let scaled = v / si.scale();
|
||||
format!("{:.2} {}{}", scaled, si.shortcode(), unit)
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user