Ruby | BigDecimal class divmod value
Last Updated :
08 Jan, 2020
BigDecimal#divmod() : divmod() is a BigDecimal class method which divided two BigDecimal value.
Syntax: BigDecimal.divmod()
Parameter: BigDecimal values to divide
Return: Quotient and Remainder of the division of two BigDecimal Value
Code #1 : Example for divmod() method
require 'bigdecimal'
a = 42 . 1 ** 13
b = -BigDecimal( "10" )
c = -( 22 ** 7 . 1 ) * 10
puts "divmod example 1 : #{a.divmod(b)}\n\n"
puts "divmod example 2 : #{b.divmod(c)}\n\n"
|
Output :
divmod example 1 : [#, #]
divmod example 2 : [#, #]
Code #2 : Example for divmod() method
require 'bigdecimal'
a = 12 ** 12 - 27
b = BigDecimal( '10' )-( 22 ** 7 . 1 ) ** 10
c = BigDecimal( '-3' )
puts "divmod example 1 : #{a.divmod(b)}\n\n"
puts "divmod example 2 : #{b.divmod(c)}\n\n"
|
Output :
divmod example 1 : [#, #]
divmod example 2 : [#, #]
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...