當前位置: 首頁>>代碼示例 >>用法及示例精選 >>正文


Ruby BigDecimal split()用法及代碼示例


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]



相關用法


注:本文由純淨天空篩選整理自mayank5326大神的英文原創作品 Ruby | BigDecimal split() function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。