The eql?()
method can be used to know if two float
values are equal. It returns a Boolean
value — i.e., either true
or false
.
floatVal.eql?(anotherFloatVal)
anotherFloatVal
: This is the float value that we want to compare with the float value floatVal
which invokes the method eql?()
.
The value returned is a Boolean
value. It returns true
if both values are equal. Otherwise, it returns false
.
# create some float valuesf1 = 34.344f2 = 2.423f3 = -5/2.3f4 = f2 / 1.0# invoke the coerce methodputs f1.eql?(f2)puts f2.eql?(f3)puts f3.eql?(f1)puts f4.eql?(f2)
f1
, f2
, f3
, and f4
, and initialize them with some values.eql?()
method, and then printed the results.