zig

fork of https://codeberg.org/ziglang/zig
Log | Files | Refs | README | LICENSE

commit ef397250554df8af8bf8fbb9c6277defe8a2de6f (tree)
parent 861b784454aa2ed3365b31dc18f9f569bc637703
Author: Boo <32691832+BanchouBoo@users.noreply.github.com>
Date:   Mon, 30 Aug 2021 13:39:05 -0400

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


Diffstat:
Mlib/std/fmt.zig | 3+--
1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/lib/std/fmt.zig b/lib/std/fmt.zig @@ -1200,8 +1200,6 @@ pub fn formatFloatDecimal( while (i < precision) : (i += 1) { try writer.writeAll("0"); } - } else { - try writer.writeAll(".0"); } } @@ -2198,6 +2196,7 @@ test "float.hexadecimal.precision" { test "float.decimal" { try expectFmt("f64: 152314000000000000000000000000", "f64: {d}", .{@as(f64, 1.52314e+29)}); try expectFmt("f32: 0", "f32: {d}", .{@as(f32, 0.0)}); + try expectFmt("f32: 0", "f32: {d:.0}", .{@as(f32, 0.0)}); try expectFmt("f32: 1.1", "f32: {d:.1}", .{@as(f32, 1.1234)}); try expectFmt("f32: 1234.57", "f32: {d:.2}", .{@as(f32, 1234.567)}); // -11.1234 is converted to f64 -11.12339... internally (errol3() function takes f64).