Open In App

Ruby | Numeric zero? function

Improve
Improve
Like Article
Like
Save
Share
Report

The zero?() is an inbuilt method in Ruby returns a boolean value. It returns true if the number is a negative one, else it returns false.

Syntax: num.zero?()

Parameters: The function needs a number which is to be checked for.

Return Value: It returns returns a boolean value.

Example 1:




# Ruby program for zero?()
# method in Numeric
  
# Initialize a number 
num1 = 0
  
# Prints zero or not 
puts num1.zero?()


Output:

true

Example 2:




# Ruby program for zero?()
# method in Numeric
  
# Initialize a number 
num1 = Complex(12, 3)
  
# Prints zero or not 
puts num1.zero?()


Output:

false

Last Updated : 19 Mar, 2024
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads