mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-11-09 23:31:23 +00:00
Show 0 instead of -0 for tiny negative graph labels
Found while testing crates/engine/src/cmd/graph/data.rs:166-172 (fmt_value) 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:
co-authored by
Claude Haiku 5.5
parent
d90cc305fa
commit
c147ae843b
@@ -169,7 +169,9 @@ pub(super) fn fmt_value(v: f64) -> String {
|
||||
// `{:.0}` prints its exact digits.
|
||||
if v.abs() < 9e18 { format!("{}", v.round() as i64) } else { format!("{v:.0}") }
|
||||
} else {
|
||||
format!("{:.2}", v).trim_end_matches('0').trim_end_matches('.').to_string()
|
||||
let s = format!("{:.2}", v).trim_end_matches('0').trim_end_matches('.').to_string();
|
||||
// A tiny negative rounds to "-0.00"; show it as plain zero like -0.0.
|
||||
if s == "-0" { "0".to_string() } else { s }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -14,6 +14,13 @@ fn fmt_value_does_not_saturate_beyond_i64() {
|
||||
assert_eq!(super::fmt_value(2.5), "2.5");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn fmt_value_tiny_negative_is_zero() {
|
||||
assert_eq!(super::fmt_value(-0.004), "0");
|
||||
assert_eq!(super::fmt_value(-0.0049), "0");
|
||||
assert_eq!(super::fmt_value(-0.006), "-0.01");
|
||||
}
|
||||
|
||||
fn graph(s: &mut Session, ty: &str) -> NodeId {
|
||||
let csv = ",2024,2025\nQ1,3,2\nQ2,5,4\nQ3,-1,6";
|
||||
NodeId(
|
||||
|
||||
Reference in New Issue
Block a user