-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Closed
Labels
A-fmtArea: `core::fmt`Area: `core::fmt`C-bugCategory: This is a bug.Category: This is a bug.T-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:
assert_eq!("1.0e3", format!("{:.1e}", 1001));
assert_eq!("1.0e3", format!("{:.1e}", 1000));
assert_eq!("1.0e3", format!("{:.1e}", 999));
I expected this all to be fine.
Instead, the final assertion fails, and the formatting is done like this in the final case:
assert_eq!("1.00e3", format!("{:.1e}", 999));
Not sure why 2 decimal places are returned, looks like a bug.
This bug also exists in the beta or nightly versions, running in Rust Playground.
Discussion: https://users.rust-lang.org/t/scientific-notation-decimal-places/99682
Edit: after looking around the compiler code for the first time I think the problem is somewhere in either format_exact or format_exact_opt.
Metadata
Metadata
Assignees
Labels
A-fmtArea: `core::fmt`Area: `core::fmt`C-bugCategory: This is a bug.Category: This is a bug.T-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.