📜  红宝石 | BigDecimal 余数()函数

📅  最后修改于: 2022-05-13 01:55:13.100000             🧑  作者: Mango

红宝石 | BigDecimal 余数()函数

BigDecimal#remainder() :remainder()是一个 BigDecimal 类方法,它将两个 BigDecimal 值相除并返回余数。

示例 #1:

# 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"

输出 :

BigDecimal a remainder b : 0.0

BigDecimal b remainder c : -0.1E2

BigDecimal a remainder c : -33978318848.0

示例 #2:

# 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"

输出 :

BigDecimal a remainder b : 0.8916100448229E13

BigDecimal b remainder c : -0.2E1

BigDecimal a remainder c : -0.3E1