strconv: fix error for string interpolation of float format (#13800)
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
|
||||
}
|
||||
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()
|
||||
|
|
|
@ -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