红宝石 |浮动 to_i() 方法
Float#to_i()是一个浮点类方法,它返回浮点值的整数表示。
Syntax: float.to_i()
Parameter: float value as argument
Return: Integer representation of the float value.
示例 #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 : 2797999
示例 #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