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

strconv: change atof64 to return an error, if the parsed value is not a valid number (#13424)

This commit is contained in:
Vincenzo Palazzo
2022-02-10 12:27:32 +01:00
committed by GitHub
parent 1c19573382
commit 7f29418c63
5 changed files with 35 additions and 9 deletions

View File

@@ -511,12 +511,12 @@ pub fn (s string) i16() i16 {
// f32 returns the value of the string as f32 `'1.0'.f32() == f32(1)`.
pub fn (s string) f32() f32 {
return f32(strconv.atof64(s))
return f32(strconv.atof64(s) or { 0 })
}
// f64 returns the value of the string as f64 `'1.0'.f64() == f64(1)`.
pub fn (s string) f64() f64 {
return strconv.atof64(s)
return strconv.atof64(s) or { 0 }
}
// u8 returns the value of the string as u8 `'1'.u8() == u8(1)`.