mirror of
https://github.com/serde-rs/json.git
synced 2026-03-11 08:19:19 +00:00
Preserve '.0' when Displaying Number
This commit is contained in:
parent
de251c8198
commit
8ba854166d
@ -294,7 +294,8 @@ impl Display for Number {
|
||||
match self.n {
|
||||
N::PosInt(u) => Display::fmt(&u, formatter),
|
||||
N::NegInt(i) => Display::fmt(&i, formatter),
|
||||
N::Float(f) => Display::fmt(&f, formatter),
|
||||
// Preserve `.0` on integral values, which Display hides
|
||||
N::Float(f) => Debug::fmt(&f, formatter),
|
||||
}
|
||||
}
|
||||
|
||||
@ -305,15 +306,6 @@ impl Display for Number {
|
||||
}
|
||||
|
||||
impl Debug for Number {
|
||||
#[cfg(not(feature = "arbitrary_precision"))]
|
||||
fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
|
||||
match self.n {
|
||||
N::PosInt(_) | N::NegInt(_) => write!(formatter, "Number({})", self),
|
||||
N::Float(f) => write!(formatter, "Number({:?})", f),
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "arbitrary_precision")]
|
||||
fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
|
||||
write!(formatter, "Number({})", self)
|
||||
}
|
||||
|
||||
@ -27,7 +27,7 @@ fn value_number() {
|
||||
assert_eq!(format!("{:?}", json!(1)), "Number(1)");
|
||||
assert_eq!(format!("{:?}", json!(-1)), "Number(-1)");
|
||||
assert_eq!(format!("{:?}", json!(1.0)), "Number(1.0)");
|
||||
assert_eq!(Number::from_f64(1.0).unwrap().to_string(), "1");
|
||||
assert_eq!(Number::from_f64(1.0).unwrap().to_string(), "1.0"); // not just "1"
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user