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


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

BigDecimal#to_d():to_d()是BigDecimal類方法,它返回Big十進製的自身。

用法:BigDecimal.to_d()

參數:BigDecimal值


返回:大十進製的自我。

示例1:

# Ruby code for BigDecimal.to_d() method 
  
# loading library 
require 'bigdecimal'
require 'bigdecimal/util'
  
# declaring bigdecimal 
a = BigDecimal("10") 
  
# declaring bigdecimal 
b = -BigDecimal("10") 
  
# declaring bigdecimal 
c = -BigDecimal("11.43") 
  
# to_d() method 
puts "BigDecimal a to_d method : #{a.to_d()}\n\n"
  
puts "BigDecimal b to_d method : #{b.to_d()}\n\n"
  
puts "BigDecimal c to_d method : #{c.to_d()}\n\n"

輸出:

BigDecimal a to_d method : 0.1E2

BigDecimal b to_d method : -0.1E2

BigDecimal c to_d method : -0.1143E2


示例2:

# Ruby code for BigDecimal.to_d() method 
  
# loading library 
require 'bigdecimal'
require 'bigdecimal/util'
  
# declaring bigdecimal 
a = BigDecimal('12')*12
  
# declaring bigdecimal 
b = BigDecimal('10')-(22 ** 7.1) ** 10
  
# declaring bigdecimal 
c = BigDecimal('-3') 
  
# to_d() method 
puts "BigDecimal a to_d method : #{a.to_d()}\n\n"
  
puts "BigDecimal b to_d method : #{b.to_d()}\n\n"
  
puts "BigDecimal c to_d method : #{c.to_d()}\n\n"

輸出:

BigDecimal a to_d method : 0.144E3

BigDecimal b to_d method : -0.20512110073058639999999999999999999999999999999999999999999999999999999999999999999999999999999E96

BigDecimal c to_d method : -0.3E1



相關用法


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