Open In App

Ruby | Float to_i() method

Last Updated : 07 Jan, 2020
Comments
Improve
Suggest changes
Like Article
Like
Report
Float#to_i() is a float class method which return a Integer representation of the float value.
Syntax: float.to_i() Parameter: float value as argument Return: Integer representation of the float value.
Example #1 : Ruby
# 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"
Output :
Integer a : 0

Integer b : 2797999
Example #2 : Ruby
# 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"
Output :
Integer a : 0

Integer b : 2999


Next Article

Similar Reads