Skip to content

Fix Lower/UpperExp formatting for integers and precision zero #89502

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

Merged
merged 2 commits into from
Oct 6, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions library/core/src/fmt/num.rs
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,6 @@ macro_rules! impl_Exp {
n /= 10;
exponent += 1;
}
let trailing_zeros = exponent;

let (added_precision, subtracted_precision) = match f.precision() {
Some(fmt_prec) => {
Expand Down Expand Up @@ -333,7 +332,7 @@ macro_rules! impl_Exp {
n += 1;
}
}
(n, exponent, trailing_zeros, added_precision)
(n, exponent, exponent, added_precision)
};

// 39 digits (worst case u128) + . = 40
Expand Down
1 change: 1 addition & 0 deletions library/core/tests/fmt/num.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ fn test_format_int_exp_precision() {
assert_eq!(format!("{:.1000e}", 1), format!("1.{}e0", "0".repeat(1000)));
//test zero precision
assert_eq!(format!("{:.0e}", 1), format!("1e0",));
assert_eq!(format!("{:.0e}", 35), format!("4e1",));

//test padding with precision (and sign)
assert_eq!(format!("{:+10.3e}", 1), " +1.000e0");
Expand Down