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(...@@ -1200,8 +1200,6 @@ pub fn formatFloatDecimal(
1200 while (i < precision) : (i += 1) {1200 while (i < precision) : (i += 1) {
1201 try writer.writeAll("0");1201 try writer.writeAll("0");
1202 }1202 }
1203 } else {
1204 try writer.writeAll(".0");
1205 }1203 }
1206 }1204 }
12071205
...@@ -2198,6 +2196,7 @@ test "float.hexadecimal.precision" {...@@ -2198,6 +2196,7 @@ test "float.hexadecimal.precision" {
2198test "float.decimal" {2196test "float.decimal" {
2199 try expectFmt("f64: 152314000000000000000000000000", "f64: {d}", .{@as(f64, 1.52314e+29)});2197 try expectFmt("f64: 152314000000000000000000000000", "f64: {d}", .{@as(f64, 1.52314e+29)});
2200 try expectFmt("f32: 0", "f32: {d}", .{@as(f32, 0.0)});2198 try expectFmt("f32: 0", "f32: {d}", .{@as(f32, 0.0)});
2199 try expectFmt("f32: 0", "f32: {d:.0}", .{@as(f32, 0.0)});
2201 try expectFmt("f32: 1.1", "f32: {d:.1}", .{@as(f32, 1.1234)});2200 try expectFmt("f32: 1.1", "f32: {d:.1}", .{@as(f32, 1.1234)});
2202 try expectFmt("f32: 1234.57", "f32: {d:.2}", .{@as(f32, 1234.567)});2201 try expectFmt("f32: 1234.57", "f32: {d:.2}", .{@as(f32, 1234.567)});
2203 // -11.1234 is converted to f64 -11.12339... internally (errol3() function takes f64).2202 // -11.1234 is converted to f64 -11.12339... internally (errol3() function takes f64).