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 :

filter_none

edit
close

play_arrow

link
brightness_4
code

# Ruby code for BigDecimal.remainder() method
  
# loading library
require 'bigdecimal'
  
# declaring bigdecimal
a = 42.1**13
  
# declaring bigdecimal
b = -BigDecimal("10")
  
# declaring bigdecimal
c = -(22 ** 7.1) * 10
  
# a
puts "BigDecimal a remainder b : #{a.remainder(b)}\n\n"
  
# b
puts "BigDecimal b remainder c : #{b.remainder(c)}\n\n"
  
# c
puts "BigDecimal a remainder c : #{c.remainder(a)}\n\n"

chevron_right


Output :

BigDecimal a remainder b : 0.0

BigDecimal b remainder c : -0.1E2

BigDecimal a remainder c : -33978318848.0

Example #2 :

filter_none

edit
close

play_arrow

link
brightness_4
code

# Ruby code for BigDecimal.remainder() method
  
# loading library
require 'bigdecimal'
  
# declaring bigdecimal
a = 12**12 - 27
  
# declaring bigdecimal
b = BigDecimal('10')-(22 ** 7.1) ** 10
  
# declaring bigdecimal
c = BigDecimal('-3')
  
# a
puts "BigDecimal a remainder b : #{a.remainder(b)}\n\n"
  
# b
puts "BigDecimal b remainder c : #{b.remainder(c)}\n\n"
  
# c
puts "BigDecimal a remainder c : #{c.remainder(a)}\n\n"

chevron_right


Output :

BigDecimal a remainder b : 0.8916100448229E13

BigDecimal b remainder c : -0.2E1

BigDecimal a remainder c : -0.3E1




My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.