method
Float
v2_6_3 -
Show latest stable
- Class:
Kernel
Float(p1, p2 = {})public
Returns arg converted to a float. Numeric types are converted directly, and with exception to string and nil the rest are converted using arg.to_f. Converting a string with invalid characters will result in a ArgumentError. Converting nil generates a TypeError. Exceptions can be suppressed by passing exception: false.
Float(1) #=> 1.0 Float("123.456") #=> 123.456 Float("123.0_badstring") #=> ArgumentError: invalid value for Float(): "123.0_badstring" Float(nil) #=> TypeError: can't convert nil into Float Float("123.0_badstring", exception: false) #=> nil