红宝石 | BigDecimal 类模值
BigDecimal#modulo() : modulo()是一个 BigDecimal 类方法,它返回两个 BigDecimal 值相除的模数。
Syntax: BigDecimal.modulo()
Parameter: BigDecimal values to divide
Return: modulus from dividing two BigDecimal values
代码 #1:模()方法的示例
# Ruby code for modulo() method
# loading BigDecimal
require 'bigdecimal'
# declaring BigDecimal
a = 42.1**13
# declaring BigDecimal
b = -BigDecimal("10")
# declaring BigDecimal
c = -(22 ** 7.1) * 10
puts "modulo example 1 : #{a.modulo(b)}\n\n"
puts "modulo example 2 : #{b.modulo(c)}\n\n"
输出 :
modulo example 1 : 0.0
modulo example 2 : -0.1E2
代码 #2:模()方法的示例
# Ruby code for modulo() method
# loading BigDecimal
require 'bigdecimal'
# declaring BigDecimal
a = 12**12 - 27
# declaring BigDecimal
b = BigDecimal('10')-(22 ** 7.1) ** 10
# declaring BigDecimal
c = BigDecimal('-3')
puts "modulo example 1 : #{a.modulo(b)}\n\n"
puts "modulo example 2 : #{b.modulo(c)}\n\n"
输出 :
modulo example 1 : -0.205121100730586399999999999999999999999999999999999999999999999999999999999999999991083899551761E96
modulo example 2 : -0.2E1