Related Articles

Related Articles

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:



filter_none

edit
close

play_arrow

link
brightness_4
code

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

chevron_right


Output :

denominator : 2

Division int/float : 2.0

Division float/float : 2.0

Example #2:

filter_none

edit
close

play_arrow

link
brightness_4
code

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

chevron_right


Output :

denominator : 1

Division int/float : 4.0

Division float/float : 4.0

My Personal Notes arrow_drop_up
Recommended Articles
Page :