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:

filter_none

edit
close

play_arrow

link
brightness_4
code

# Ruby code for zero?() method
  
# Initializing value 
a = -100.7 * 0
b = -0
c = (22 + 7.1) * 4
   
# Printing  a
puts "a is zero : #{a.zero?}\n\n"
   
# Printing b
puts "b is zero : #{b.zero?}\n\n"
   
# Printing c
puts "c is zero : #{c.zero?}\n\n"

chevron_right


Output :

a is zero : true

b is zero : true

c is zero : false

Example #2:

filter_none

edit
close

play_arrow

link
brightness_4
code

# Ruby code for zero?() method
  
# Initializing value 
a = 2.0
b = 0.000000001
  
# Printing result 
puts "a is zero : #{a.zero?}\n\n"
puts "b is zero : #{b.zero?}\n\n"

chevron_right


Output :

a is zero : false

b is zero : false



My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.