types.String.tofloat
Method on every
stringParses str as a float.
Return value
str parsed as a float, using the same syntax the compiler accepts for a float literal.
Errors
Throws cannot convert the string to float when str does not parse as a number.
Notes
Takes no arguments beyond the string itself; unlike types.String.tointeger, there is no base to pass, and the check is exact (calling it with an extra argument throws a wrong-number-of-parameters error rather than ignoring it).
Example
println("\"3.5\".tofloat() =", "3.5".tofloat())
println("\"42\".tofloat() =", "42".tofloat())
try { "abc".tofloat() } catch (e) println("\"abc\".tofloat() throws:", e)Output:
"3.5".tofloat() = 3.5
"42".tofloat() = 42
"abc".tofloat() throws: cannot convert the string to floatSee also
tointeger | Parses str as an integer. |
| string | class index |