diff --git a/vlib/v/scanner/scanner.v b/vlib/v/scanner/scanner.v index 08e91a6fe8c6b6..533a78cc3b8a3c 100644 --- a/vlib/v/scanner/scanner.v +++ b/vlib/v/scanner/scanner.v @@ -475,7 +475,7 @@ fn (mut s Scanner) ident_dec_number() string { } // scan exponential part mut has_exp := false - if s.pos < s.text.len && s.text[s.pos] in [`e`, `E`] { + if s.pos < s.text.len && s.text[s.pos] in [`e`, `E`] && !s.is_inside_string { has_exp = true s.pos++ if s.pos < s.text.len && s.text[s.pos] in [`-`, `+`] { @@ -505,7 +505,7 @@ fn (mut s Scanner) ident_dec_number() string { if !s.pref.translated { s.error('this number has unsuitable digit `${first_wrong_digit.str()}`') } - } else if s.text[s.pos - 1] in [`e`, `E`] { + } else if s.text[s.pos - 1] in [`e`, `E`] && !s.is_inside_string { // error check: 5e s.pos-- // adjust error position s.error('exponent has no digits') diff --git a/vlib/v/tests/builtin_strings_and_interpolation/string_interpolation_test.v b/vlib/v/tests/builtin_strings_and_interpolation/string_interpolation_test.v index 4fdea216a3f48e..95d67fa733f953 100644 --- a/vlib/v/tests/builtin_strings_and_interpolation/string_interpolation_test.v +++ b/vlib/v/tests/builtin_strings_and_interpolation/string_interpolation_test.v @@ -233,3 +233,10 @@ fn test_interpo_non_ascii_characters() { hello := '你好' assert '${hello},世界!' == '你好,世界!' } + +fn test_float_exponent_sign() { + a := 1234567.0123456e03 + assert '${a:6.1e}' == '1.2e+09' + assert '${a:6.2e}' == '1.23e+09' + assert '${a:6.5e}' == '1.23457e+09' +}