parsingcastingvlang

Parse float from string (v-lang)


How to convert string values like '2 263.32', '592.06' to float numbers (f64) in V-language?

UPD: solved in this way:

'1 456.93'.replace(' ', '').f32() == (float) 1456.93.

Of courcse, this is a workaround and won't work with strings like '$1,592.13'.


Solution

  • Try '592.06'.f64(). I don't think having a whitespace in the number will work currently but you can use underscore instead: '2_263.32'.f64()