mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
strconv: fix error for string interpolation of float format (#13800)
This commit is contained in:
parent
afbccf79f7
commit
56f5ed4789
@ -274,10 +274,13 @@ pub fn f64_to_str_lnd1(f f64, dec_digit int) string {
|
||||
|
||||
// println("r_i-d_pos: ${r_i - d_pos}")
|
||||
if dot_res_sp >= 0 {
|
||||
if (r_i - dot_res_sp) > dec_digit {
|
||||
r_i = dot_res_sp + dec_digit + 1
|
||||
}
|
||||
r_i = dot_res_sp + dec_digit + 1
|
||||
res[r_i] = 0
|
||||
for c1 in 1 .. dec_digit + 1 {
|
||||
if res[r_i - c1] == 0 {
|
||||
res[r_i - c1] = `0`
|
||||
}
|
||||
}
|
||||
// println("result: [${tos(&res[0],r_i)}]")
|
||||
tmp_res := tos(res.data, r_i).clone()
|
||||
res.free()
|
||||
|
13
vlib/v/tests/string_interpolation_float_fmt_test.v
Normal file
13
vlib/v/tests/string_interpolation_float_fmt_test.v
Normal file
@ -0,0 +1,13 @@
|
||||
fn test_string_interpolation_float_fmt() {
|
||||
mut a := 76.295
|
||||
eprintln('${a:8.2}')
|
||||
assert '${a:8.2}' == ' 76.30'
|
||||
eprintln('${a:8.2f}')
|
||||
assert '${a:8.2f}' == ' 76.30'
|
||||
|
||||
a = 76.296
|
||||
eprintln('${a:8.2}')
|
||||
assert '${a:8.2}' == ' 76.30'
|
||||
eprintln('${a:8.2f}')
|
||||
assert '${a:8.2f}' == ' 76.30'
|
||||
}
|
Loading…
Reference in New Issue
Block a user