-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Closed
Labels
A-docsArea: Documentation for any part of the project, including the compiler, standard library, and toolsArea: Documentation for any part of the project, including the compiler, standard library, and toolsA-floating-pointArea: Floating point numbers and arithmeticArea: Floating point numbers and arithmeticT-libsRelevant to the library team, which will review and decide on the PR/issue.Relevant to the library team, which will review and decide on the PR/issue.
Description
I tried this code:
println!("{:.0}", 10.5f64);
I expected to see this happen: It prints 11
Instead, this happened: It prints 10
As far as I am able to find 10.5 has a perfect (lossless) representation in f64-space so it does not seem to be because of floating point error to me.
If I put in 9.5 instead it does work as expected (it prints 10), which is weird because that also has a perfect representation as f64. Is it applying a round_ties_even() kind of logic? If it is then I would expect this to be documented e.g. under https://doc.rust-lang.org/std/fmt/#precision
Meta
I've been using rust playground, rust version 1.70.0
Metadata
Metadata
Assignees
Labels
A-docsArea: Documentation for any part of the project, including the compiler, standard library, and toolsArea: Documentation for any part of the project, including the compiler, standard library, and toolsA-floating-pointArea: Floating point numbers and arithmeticArea: Floating point numbers and arithmeticT-libsRelevant to the library team, which will review and decide on the PR/issue.Relevant to the library team, which will review and decide on the PR/issue.