properly omit negative for values that round to zero
This commit is contained in:
parent
75b896fe3d
commit
90b940fd7d
@ -165,10 +165,6 @@ from_integer!(u8);
|
|||||||
|
|
||||||
impl Display for Number {
|
impl Display for Number {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
if self.val.is_negative() {
|
|
||||||
f.write_char('-')?;
|
|
||||||
}
|
|
||||||
|
|
||||||
let mut whole = self.val.to_integer().abs();
|
let mut whole = self.val.to_integer().abs();
|
||||||
let mut dec = String::new();
|
let mut dec = String::new();
|
||||||
|
|
||||||
@ -218,6 +214,10 @@ impl Display for Number {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if self.val.is_negative() && (!whole.is_zero() || !dec.is_empty()) {
|
||||||
|
f.write_char('-')?;
|
||||||
|
}
|
||||||
write!(f, "{}", whole)?;
|
write!(f, "{}", whole)?;
|
||||||
write!(f, "{}", dec)?;
|
write!(f, "{}", dec)?;
|
||||||
Ok(())
|
Ok(())
|
||||||
|
@ -81,3 +81,8 @@ test!(
|
|||||||
"a {\n color: 1 + 3/4;\n}\n",
|
"a {\n color: 1 + 3/4;\n}\n",
|
||||||
"a {\n color: 1.75;\n}\n"
|
"a {\n color: 1.75;\n}\n"
|
||||||
);
|
);
|
||||||
|
test!(
|
||||||
|
negative_near_zero_no_sign,
|
||||||
|
"a {\n color: -0.000000000001;\n}\n",
|
||||||
|
"a {\n color: 0;\n}\n"
|
||||||
|
);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user