Skip to content

End of Life Ruby 3.2 has reached end of life and gets no more fixes. Switch to Ruby 4.0 →

instance method

Integer#to_f

to_f → float

Converts self to a Float:

Example
1.to_f  # => 1.0
-1.to_f # => -1.0

If the value of self does not fit in a Float, the result is infinity:

Example
(10**400).to_f  # => Infinity
(-10**400).to_f # => -Infinity
See also #to_d #to_i #to_bn #to_int also in 4.1 · 4.0 · 3.4 · 3.3 · 3.1 · 3.0