From 54a02996f2aea695973b77fb72913c9b16cb5b1d Mon Sep 17 00:00:00 2001 From: yuyi Date: Thu, 16 Apr 2020 13:30:25 +0800 Subject: [PATCH] cgen: fix string interpolation float type --- vlib/math/complex/complex.v | 6 +++--- vlib/v/gen/cgen.v | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/vlib/math/complex/complex.v b/vlib/math/complex/complex.v index c4602a014c..a879f6ec81 100644 --- a/vlib/math/complex/complex.v +++ b/vlib/math/complex/complex.v @@ -18,12 +18,12 @@ pub fn complex(re f64, im f64) Complex { // To String method pub fn (c Complex) str() string { - mut out := '$c.re' + mut out := '${c.re:f}' out += if c.im >= 0 { - '+$c.im' + '+${c.im:f}' } else { - '$c.im' + '${c.im:f}' } out += 'i' return out diff --git a/vlib/v/gen/cgen.v b/vlib/v/gen/cgen.v index fcb41e6db9..e138e62d1a 100644 --- a/vlib/v/gen/cgen.v +++ b/vlib/v/gen/cgen.v @@ -2222,7 +2222,7 @@ fn (g mut Gen) string_inter_literal(node ast.StringInterLiteral) { [.enum_, .array, .array_fixed] { g.write('%.*s') } else if node.expr_types[i] in [table.f32_type, table.f64_type] { - g.write('%f') + g.write('%g') } else { g.write('%d') }