authorgravatar for 32691832+BanchouBoo@users.noreply.github.comBoo <32691832+BanchouBoo@users.noreply.github.com> 2021-08-30 13:39:05-04:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2021-08-30 13:39:05-04:00
logef397250554df8af8bf8fbb9c6277defe8a2de6f
treee61b15508cb671293f5f7105942da686a2af77ea
parent861b784454aa2ed3365b31dc18f9f569bc637703
signaturebadge-question-mark Signed by PGP key 4AEE18F83AFDEB23

Fix float formatting for 0.0 when precision is 0 (#9642)


1 files changed, 1 insertions(+), 2 deletions(-)

lib/std/fmt.zig+1-2
......@@ -1200,8 +1200,6 @@ pub fn formatFloatDecimal(
12001200 while (i < precision) : (i += 1) {
12011201 try writer.writeAll("0");
12021202 }
1203 } else {
1204 try writer.writeAll(".0");
12051203 }
12061204 }
12071205
......@@ -2198,6 +2196,7 @@ test "float.hexadecimal.precision" {
21982196test "float.decimal" {
21992197 try expectFmt("f64: 152314000000000000000000000000", "f64: {d}", .{@as(f64, 1.52314e+29)});
22002198 try expectFmt("f32: 0", "f32: {d}", .{@as(f32, 0.0)});
2199 try expectFmt("f32: 0", "f32: {d:.0}", .{@as(f32, 0.0)});
22012200 try expectFmt("f32: 1.1", "f32: {d:.1}", .{@as(f32, 1.1234)});
22022201 try expectFmt("f32: 1234.57", "f32: {d:.2}", .{@as(f32, 1234.567)});
22032202 // -11.1234 is converted to f64 -11.12339... internally (errol3() function takes f64).