Skip to content

Maintenance Ruby 3.3 gets fixes, but no new features. 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.2 · 3.1 · 3.0