mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-11-01 05:37:23 -06:00
Show 0.00 instead of -0.00 in Unit::readout for tiny negatives
Found while testing crates/doc/src/units.rs:163-165 (readout) Co-Authored-By: Claude Haiku 5.5 <noreply@anthropic.com> Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
committed by
bflatastic
co-authored by
Claude Haiku 5.5
parent
a5a7c4638a
commit
d0e1a045c1
@@ -144,3 +144,10 @@ fn mixed_mul_div() {
|
||||
assert_eq!(Unit::Points.parse("10*2/5"), Some(4.0));
|
||||
assert_eq!(Unit::Points.parse("10*2/5 px"), Some(Unit::Pixels.to_pt(4.0)));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn readout_has_no_negative_zero() {
|
||||
assert_eq!(Unit::Points.readout(-0.001), "0.00 pt");
|
||||
assert_eq!(Unit::Points.readout(-0.0), "0.00 pt");
|
||||
assert_eq!(Unit::Points.readout(-12.5), "-12.50 pt");
|
||||
}
|
||||
|
||||
@@ -161,7 +161,10 @@ impl Unit {
|
||||
/// A point value as the canvas measurement labels show it: two decimals and the suffix
|
||||
/// (`12.50 mm`).
|
||||
pub fn readout(self, pt: f64) -> String {
|
||||
format!("{:.2} {}", self.from_pt(pt), self.suffix())
|
||||
let s = format!("{:.2}", self.from_pt(pt));
|
||||
// A small negative value rounds to `-0.00`; show it as `0.00`.
|
||||
let s = if s == "-0.00" { "0.00" } else { &s };
|
||||
format!("{} {}", s, self.suffix())
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user