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。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。