Skip to content

Commit e3996ff

Browse files
committed
Fix Lower/UpperExp formatting for integers and precision zero
1 parent edebf77 commit e3996ff

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

library/core/src/fmt/num.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,6 @@ macro_rules! impl_Exp {
305305
n /= 10;
306306
exponent += 1;
307307
}
308-
let trailing_zeros = exponent;
309308

310309
let (added_precision, subtracted_precision) = match f.precision() {
311310
Some(fmt_prec) => {
@@ -333,7 +332,7 @@ macro_rules! impl_Exp {
333332
n += 1;
334333
}
335334
}
336-
(n, exponent, trailing_zeros, added_precision)
335+
(n, exponent, exponent, added_precision)
337336
};
338337

339338
// 39 digits (worst case u128) + . = 40

library/core/tests/fmt/num.rs

+1
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ fn test_format_int_exp_precision() {
146146
assert_eq!(format!("{:.1000e}", 1), format!("1.{}e0", "0".repeat(1000)));
147147
//test zero precision
148148
assert_eq!(format!("{:.0e}", 1), format!("1e0",));
149+
assert_eq!(format!("{:.0e}", 25), format!("3e1",));
149150

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

0 commit comments

Comments
 (0)