Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Preserve '.0' when Displaying Number #919

merged 3 commits into from Aug 21, 2022

Preserve '.0' when Displaying Number #919

merged 3 commits into from Aug 21, 2022


Copy link

@dtolnay dtolnay commented Aug 21, 2022

Tiny followup to #918.

let number: serde_json::Number = serde_json::from_str("1.0").unwrap();
println!("{}", number);

Previously: 1
Now: 1.0

src/ Outdated
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),
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually we should just serialize using ryu and itoa, like the Serializer does, or maybe even go through the Serializer itself. std::fmt produces a worse representation for floats, like 120000000000000000000000000000000000000000 instead of 1.2e41.

@dtolnay dtolnay merged commit 2c8e2b0 into master Aug 21, 2022
32 checks passed
@dtolnay dtolnay deleted the displaynum branch August 21, 2022 21:07
Copy link

shouldn't this be a more significant version bump than patch? it has broken a unit test of mine. nothing extreme but was not expecting to see this behavior change

Copy link

rustaceans are afraid of MAJOR semvar version changes. it's like kryptonite to them.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet

Successfully merging this pull request may close these issues.

None yet

3 participants