Ruby Float eql()方法
eql()是一个float类的方法,用于检查两个值是否相等。
语法:float.eql()
参数:要检查的浮点数值
返回:布尔值布尔值
如果数值相等则返回true,否则返回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