Skip to content
Related Articles

Related Articles

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

Float divmod() is a float class method which return an array having the quotient and remainder on dividing two numbers.

Syntax: float.divmod()

Parameter: float values – dividend and divisor

Return: An array with quotient and remainder.

Exxample #1:






# Ruby code for divmod() method
  
# Initializing value
a = 4.0
b = 2.0
  
# Printing result
puts "Division a/b : #{a.divmod(b)}\n\n"
puts "Division b/a : #{b.divmod(a)}\n\n"

Output :

Division a/b : [2, 0.0]

Division b/a : [0, 2.0]

Example #2:




# Ruby program for divmod() method
  
# Initializing value
a = 0
b = 2.0
  
# dividing by zero - gives error
puts "Division a/b : #{a.divmod(b)}\n\n"
puts "Division b/a : #{b.divmod(a)}\n\n"

Output :

source_file.rb:8:in `divmod': divided by 0 (ZeroDivisionError)
    from source_file.rb:8:in `'

Division a/b : [0, 0.0]
My Personal Notes arrow_drop_up
Recommended Articles
Page :