Casting to a Float
suggest change"123.50".to_f #=> 123.5
Float("123.50") #=> 123.5
However, there is a difference when the string is not a valid Float
:
"something".to_f #=> 0.0
Float("something") # ArgumentError: invalid value for Float(): "something"
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents