diff --git a/src/format.rs b/src/format.rs index d536ab96..74047643 100644 --- a/src/format.rs +++ b/src/format.rs @@ -37,16 +37,17 @@ pub fn short(n: f64) -> String { fn signed_short(n: f64) -> String { let n_abs = n.abs(); + let sign = if n >= 0.0 { '+' } else { '\u{2212}' }; if n_abs < 10.0 { - format!("{:+.4}", n) + format!("{}{:.4}", sign, n_abs) } else if n_abs < 100.0 { - format!("{:+.3}", n) + format!("{}{:.3}", sign, n_abs) } else if n_abs < 1000.0 { - format!("{:+.2}", n) + format!("{}{:.2}", sign, n_abs) } else if n_abs < 10000.0 { - format!("{:+.1}", n) + format!("{}{:.1}", sign, n_abs) } else { - format!("{:+.0}", n) + format!("{}{:.0}", sign, n_abs) } } @@ -124,7 +125,7 @@ mod test { while float > -999_999.9 { let string = signed_short(float); println!("{}", string); - assert!(string.len() <= 7); + assert!(string.chars().count() <= 7); float *= 2.0; } }