diff --git a/vlib/builtin/float.c.v b/vlib/builtin/float.c.v index 2a2481688a..ac489dc495 100644 --- a/vlib/builtin/float.c.v +++ b/vlib/builtin/float.c.v @@ -85,10 +85,10 @@ pub fn (x f32) str() string { f: x } if f.u == strconv.single_minus_zero { - return '-0.' + return '-0.0' } if f.u == strconv.single_plus_zero { - return '0.' + return '0.0' } } abs_x := f32_abs(x) diff --git a/vlib/builtin/float_test.v b/vlib/builtin/float_test.v index 1a68bb6386..d2514c5a38 100644 --- a/vlib/builtin/float_test.v +++ b/vlib/builtin/float_test.v @@ -228,3 +228,12 @@ fn test_float_point_formatting_rounding() { assert '${-239.55555555555:0.1f}' == '-239.6' assert '${-239.55555555555:0.0f}' == '-240' } + +fn test_float_zero_str() { + f1 := f32(0.0) + f2 := 0.0 + assert f1.str() == '0.0' + assert '$f1' == '0.0' + assert f2.str() == '0.0' + assert '$f2' == '0.0' +}