BigDecimal#split():split()是BigDecimal類方法,它將BigDecimal數分為四個部分,以值數組形式返回。
用法:BigDecimal.split()
參數:BigDecimal值
返回:- 標誌
– significant_digits
–基礎
–指數
示例1:
# Ruby code for BigDecimal.split() method
# loading library
require 'bigdecimal'
# declaring bigdecimal
a = BigDecimal("10")
# declaring bigdecimal
b = -BigDecimal("10")
# declaring bigdecimal
c = -BigDecimal("11.43")
# split() method
puts "BigDecimal a split method : #{a.split()}\n\n"
puts "BigDecimal b split method : #{b.split()}\n\n"
puts "BigDecimal a split method : #{c.split()}\n\n"
輸出:
BigDecimal a split method : [1, "1", 10, 2] BigDecimal b split method : [-1, "1", 10, 2] BigDecimal a split method : [-1, "1143", 10, 2]
示例2:
# Ruby code for BigDecimal.split() method
# loading library
require 'bigdecimal'
# declaring bigdecimal
a = BigDecimal('12')*12
# declaring bigdecimal
b = BigDecimal('10')-(22 ** 7.1) ** 10
# declaring bigdecimal
c = BigDecimal('-3')
# split() method
puts "BigDecimal a split method : #{a.split()}\n\n"
puts "BigDecimal b split method : #{b.split()}\n\n"
puts "BigDecimal a split method : #{c.split()}\n\n"
輸出:
BigDecimal a split method : [1, "144", 10, 3] BigDecimal b split method : [-1, "20512110073058639999999999999999999999999999999999999999999999999999999999999999999999999999999", 10, 96] BigDecimal a split method : [-1, "3", 10, 1]
相關用法
- Ruby BigDecimal E()用法及代碼示例
- Ruby BigDecimal sub()用法及代碼示例
- Ruby BigDecimal sin()用法及代碼示例
- Ruby BigDecimal PI()用法及代碼示例
- Ruby BigDecimal quo()用法及代碼示例
- Ruby BigDecimal exp()用法及代碼示例
- Ruby BigDecimal cos()用法及代碼示例
- Ruby BigDecimal zero?()用法及代碼示例
- Ruby BigDecimal log()用法及代碼示例
- Ruby BigDecimal remainder()用法及代碼示例
- Ruby BigDecimal precs用法及代碼示例
- Ruby BigDecimal to_r()用法及代碼示例
- Ruby BigDecimal to_digits()用法及代碼示例
- Ruby BigDecimal to_int()用法及代碼示例
- Ruby BigDecimal sqrt()用法及代碼示例
注:本文由純淨天空篩選整理自mayank5326大神的英文原創作品 Ruby | BigDecimal split() function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。