红宝石 |浮动 eql() 方法
eql()是一个浮点类方法,用于检查两个值是否相等。
Syntax: float.eql()
Parameter: float values which is to be checked
Return: Boolean value
return true if values are equal otherwise return false
示例 #1:
# Ruby code for equal() method
# Declaring float value
a = -100.7
# Declaring float value
b = -100.70
# Declaring float value
c = 100.7
# Check array equality
puts "a = b : #{a.eql?(b)}\n\n"
# Check array equality
puts "b = c : #{b.eql?(c)}\n\n"
# Check array equality
puts "c = b : #{c.eql?(b)}\n\n"
输出 :
a = b : true
b = c : false
c = b : false
示例 #2:
# Ruby code for equal() method
# declaring float value
a = 10070
# Declaring float value
b = 10070
# Declaring float value
c = 10070.0
# Check array equality
puts "a = b : #{a.eql?(b)}\n\n"
# Check array equality
puts "b = c : #{b.eql?(c)}\n\n"
# Check array equality
puts "c = b : #{c.eql?(b)}\n\n"
输出 :
a = b : true
b = c : false
c = b : false