Ruby Float zero?() method with example
Float#zero() : zero() is a float class method which checks whether the float value is zero.
Syntax: float.zero()
Parameter:float value which is to be checked
Return: Boolean value return true if value is zero otherwise return false
Example #1:
a = - 100 . 7 * 0
b = - 0
c = ( 22 + 7 . 1 ) * 4
puts "a is zero : #{a.zero?}\n\n"
puts "b is zero : #{b.zero?}\n\n"
puts "c is zero : #{c.zero?}\n\n"
|
Output :
a is zero : true
b is zero : true
c is zero : false
Example #2:
a = 2 . 0
b = 0 . 000000001
puts "a is zero : #{a.zero?}\n\n"
puts "b is zero : #{b.zero?}\n\n"
|
Output :
a is zero : false
b is zero : false
Last Updated :
07 Jan, 2020
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...