1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

builtin,strconv: append ".0", to float string representations, to ensure clarity (#16079)

This commit is contained in:
Subhomoy Haldar
2022-10-17 13:41:07 +01:00
committed by GitHub
parent 29b1796791
commit 43b9a716c5
21 changed files with 98 additions and 74 deletions

View File

@ -19,10 +19,10 @@ pub fn (x f64) str() string {
f: x
}
if f.u == strconv.double_minus_zero {
return '-0'
return '-0.0'
}
if f.u == strconv.double_plus_zero {
return '0'
return '0.0'
}
}
abs_x := f64_abs(x)
@ -37,11 +37,11 @@ pub fn (x f64) str() string {
[inline]
pub fn (x f64) strg() string {
if x == 0 {
return '0'
return '0.0'
}
abs_x := f64_abs(x)
if abs_x >= 0.0001 && abs_x < 1.0e6 {
return strconv.f64_to_str_l_no_dot(x)
return strconv.f64_to_str_l_with_dot(x)
} else {
return strconv.ftoa_64(x)
}
@ -85,10 +85,10 @@ pub fn (x f32) str() string {
f: x
}
if f.u == strconv.single_minus_zero {
return '-0'
return '-0.'
}
if f.u == strconv.single_plus_zero {
return '0'
return '0.'
}
}
abs_x := f32_abs(x)
@ -103,11 +103,11 @@ pub fn (x f32) str() string {
[inline]
pub fn (x f32) strg() string {
if x == 0 {
return '0'
return '0.0'
}
abs_x := f32_abs(x)
if abs_x >= 0.0001 && abs_x < 1.0e6 {
return strconv.f32_to_str_l_no_dot(x)
return strconv.f32_to_str_l_with_dot(x)
} else {
return strconv.ftoa_32(x)
}