Ruby | BigDecimal remainder() function
BigDecimal#remainder() : remainder() is a BigDecimal class method which divides the two BigDecimal values and returns the remainder value.
Syntax: BigDecimal.remainder()
Parameter: BigDecimal values
Return: divides the two BigDecimal values and returns the remainder value.
Example #1 :
require 'bigdecimal'
a = 42 . 1 ** 13
b = -BigDecimal( "10" )
c = -( 22 ** 7 . 1 ) * 10
puts "BigDecimal a remainder b : #{a.remainder(b)}\n\n"
puts "BigDecimal b remainder c : #{b.remainder(c)}\n\n"
puts "BigDecimal a remainder c : #{c.remainder(a)}\n\n"
|
Output :
BigDecimal a remainder b : 0.0
BigDecimal b remainder c : -0.1E2
BigDecimal a remainder c : -33978318848.0
Example #2 :
require 'bigdecimal'
a = 12 ** 12 - 27
b = BigDecimal( '10' )-( 22 ** 7 . 1 ) ** 10
c = BigDecimal( '-3' )
puts "BigDecimal a remainder b : #{a.remainder(b)}\n\n"
puts "BigDecimal b remainder c : #{b.remainder(c)}\n\n"
puts "BigDecimal a remainder c : #{c.remainder(a)}\n\n"
|
Output :
BigDecimal a remainder b : 0.8916100448229E13
BigDecimal b remainder c : -0.2E1
BigDecimal a remainder c : -0.3E1
Last Updated :
05 Dec, 2019
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...