BigDecimal#remainder():remainder()是BigDecimal類方法,該方法將兩個BigDecimal值相除並返回餘數。
用法:BigDecimal.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
相關用法
- Ruby Integer remainder()用法及代碼示例
- Ruby Numeric remainder()用法及代碼示例
- Ruby BigDecimal exp()用法及代碼示例
- Ruby BigDecimal log()用法及代碼示例
- Ruby BigDecimal cos()用法及代碼示例
- Ruby BigDecimal E()用法及代碼示例
- Ruby BigDecimal sin()用法及代碼示例
- Ruby BigDecimal quo()用法及代碼示例
- Ruby BigDecimal sub()用法及代碼示例
- Ruby BigDecimal PI()用法及代碼示例
- Ruby BigDecimal zero?()用法及代碼示例
- Ruby BigDecimal truncate()用法及代碼示例
- Ruby BigDecimal to_f()用法及代碼示例
- Ruby BigDecimal atan()用法及代碼示例
- Ruby BigDecimal to_s()用法及代碼示例
注:本文由純淨天空篩選整理自mayank5326大神的英文原創作品 Ruby | BigDecimal remainder() function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。