Open In App

Ruby Float zero?() method with example

Last Updated : 07 Jan, 2020
Improve
Improve
Like Article
Like
Save
Share
Report

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:




# 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"


Output :

a is zero : true

b is zero : true

c is zero : false

Example #2:




# 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"


Output :

a is zero : false

b is zero : false

Similar Reads

Ruby Float to_r() method with example
Float to_r() is a float class method which return a rational form of the float value. Syntax: float.to_r() Parameter: float value as argument Return: Rational form representation of the float value. Example #1 : # Ruby code for to_r() method # Initializing values a = 2.0 b = 9.99991 # Printing result puts "Rational form of a : #{a.to_r}\n\n
1 min read
Ruby Float coerce() method with example
coerce() is a float class method which return the ceil value of the passed float value. Syntax: float.coerce() Parameter: numeric values (can be integer as well as float value) Return: An array with both float and numeric value represented in the form of Float objects. Example #1 : # Ruby code for coerce() method # ceil value of the float value put
1 min read
Ruby Float to_d() - BigDecimal method with example
Float to_d() is a float class method which return a BigDecimal representation of the float value Syntax: float.to_d() Parameter: float value as argument precision parameter : number of significant digits for the result Return: BigDecimal representation of the float value with a significant number of digits for the result. Example #1 : C/C++ Code #
1 min read
Ruby Float rationalize() method with example
Float rationalize() is a float class method which return the simple rational form (p/q) of a float value. Syntax: float.rationalize() Parameter: float value as argument Return: Simple approximation value Example #1: # Ruby program for rationalize() method # Initialize value a = 0.767 b = 2999.011 # Printing result puts "Rationalizing a : #{a.r
1 min read
Ruby Float quo() method with example
Float quo() is a float class method which return the quotient value of the division. Syntax: float.quo() Parameter: float values - dividend and divisor Return: Quotient value of the division. Example #1: # Ruby code for quo() method # Initializing value a = 4.0 b = 2.0 # Printing result puts "Division a/b : #{a.quo(b)}\n\n" puts "Div
1 min read
Ruby Float prev_float() method with example
Float prev_float() is a float class method which returns the previous representation of the floating point number. Syntax: float.prev_float() Parameter: float value to be passed Return: Previous representation of the floating point number. Example #1: # Ruby code for prev_float() method # Initializing value a = 26.00/ 3 b = 8.0999 c = 3 + 105.003 #
1 min read
Ruby Float next_float() method with example
Float next_float() is a float class method which returns the next representation of the floating point number. Syntax: float.next_float() Parameter: float value to be passed Return: Next representation of the floating point number. Example #1: # Ruby program for next_float() method # Initializing value a = 26.00/ 3 b = 8.0999 c = 3 + 105.003 # Prin
1 min read
Ruby Float nan?() method with example
Float nan?() is a float class method that checks whether the value is 'not a number'. 'Not A Number' means an invalid IEEE floating-point number. Syntax: float.nan?()Parameter: float value to be passedReturn: Return true - if the value is 'not a number' otherwise return false Example #1: C/C++ Code # Ruby program for nan?() method # Initializing va
1 min read
Ruby Float modulo() method with example
Float modulo() is a float class method which return the remainder value on dividing two float values. Syntax: float.modulo() Parameter: remainder value from the operation p/q Return: Modulo i.e. Remainder Example #1: Example for modulo() method # Ruby program for modulo() method # Initilizig value a = 26.00 b = 8.0 # Printing result puts "nume
1 min read
Ruby Float magnitude() method with example
Float magnitude() is a float class method which works on float values and converts them to the absolute form. Syntax: float.magnitude() Parameter: float value which is to be converted to absolute value Return: absolute value of the passed float value Example #1: # Ruby program for magnitude() method # Initializing value a = -56.23333333 b = -10000.
1 min read