Skip to content
Related Articles

Related Articles

Improve Article

Ruby Float denominator() method with example

  • Last Updated : 07 Jan, 2020

Float#denominator() : denominator() is a float class method which return a float value as the denominator value for p/q form.

Syntax: float.denominator()

Parameter: float value (q) for the p/q form. [Always positive]

Return: A machine-dependent result.

Example #1:






# Ruby code for denominator() method
  
# Initialize value
a = 2.5.denominator()
  
# Printing result
puts "denominator : #{a}\n\n"
puts "Division int/float : #{4.fdiv(a)}\n\n"
puts "Division float/float : #{4.0.fdiv(a)}\n\n"

Output :

denominator : 2

Division int/float : 2.0

Division float/float : 2.0

Example #2:




# Ruby code for denominator() method
  
# Initialize value
a = 0.denominator()
  
# returning machine dependent result
puts "denominator : #{a}\n\n"
puts "Division int/float : #{4.fdiv(a)}\n\n"
puts "Division float/float : #{4.0.fdiv(a)}\n\n"

Output :

denominator : 1

Division int/float : 4.0

Division float/float : 4.0

My Personal Notes arrow_drop_up
Recommended Articles
Page :