Closed
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.