Skip to content
Related Articles

Related Articles

Ruby Float fdiv() method with example
  • Last Updated : 07 Jan, 2020

Float fdiv() is a float class method which return a division value of the form p/q.

Syntax: float.fdiv()

Parameter: values to divide – p and q

Return: Division value – Quotient

Example #1:






# Ruby program for fdiv() method
  
# Initializing value
a = 2.0.numerator()
  
# returning machine dependent result
puts "numerator : #{a}\n\n"
  
# using as a numerator
puts "Division int/float : #{a.fdiv(4)}\n\n"
puts "Division float/float : #{a.fdiv(4.0)}\n\n"

Output :

numerator : 2

Division int/float : 0.5

Division float/float : 0.5

Example #2:




# Ruby program for fdiv() method
  
# Initializing value
a = 0.numerator()
  
# Printing result
puts "numerator : #{a}\n\n"
puts "Division int/float : #{a.fdiv(4)}\n\n"
puts "Division float/float : #{a.fdiv(4.0)}\n\n"

Output :

numerator : 0

Division int/float : 0.0

Division float/float : 0.0

Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.

My Personal Notes arrow_drop_up
Recommended Articles
Page :