Float#to_i() is a float class method which return a Integer representation of the float value.
Ruby
Output :
Ruby
Output :
Syntax: float.to_i() Parameter: float value as argument Return: Integer representation of the float value.Example #1 :
# Ruby code for to_i() method
# declaring float value
a = 0.756567
# declaring float value
b = 2797999.011
# converting to integer
puts "Integer a : #{a.to_i}\n\n"
# converting to integer
puts "Integer b : #{b.to_i}\n\n"
Integer a : 0 Integer b : 2797999Example #2 :
# Ruby code for to_i() method
# declaring float value
a = 0.767
# declaring float value
b = 2999.011
# converting to integer
puts "Integer a : #{a.to_i}\n\n"
# converting to integer
puts "Integer b : #{b.to_i}\n\n"
Integer a : 0 Integer b : 2999