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


Ruby BigDecimal nonzero?用法及代碼示例


BigDecimal#nonzero?():nonzero?()是BigDecimal類方法,它檢查BigDecimal值是否為非零。

用法: BigDecimal.nonzero?()

參數:要檢查的BigDecimal值


返回:self:如果值非零;否則為零

代碼1:非零示例?

# Ruby code for nonzero?() method 
  
# loading BigDecimal 
require 'bigdecimal'
  
# declaring BigDecimal 
a = 42.1**13
  
# declaring BigDecimal 
b = -BigDecimal("10") 
  
# declaring BigDecimal 
c = -(22 ** 7.1) * 10
  
puts "nonzero? example 1:#{a.nonzero?()}\n\n"
  
puts "nonzero? example 2:#{b.nonzero?()}\n\n"
  
puts "nonzero? example 3:#{c.nonzero?()}\n\n"
     

輸出:

nonzero? example 1:1.3051704902006439e+21

nonzero? example 2:-0.1E2

nonzero? example 3:-33978252067.813686

代碼2:非零示例?

# Ruby code for nonzero?() method 
  
# loading BigDecimal 
require 'bigdecimal'
  
# declaring BigDecimal 
b = BigDecimal('10')-(22 ** 7.1) ** 10
  
# declaring BigDecimal 
c = BigDecimal('-3') 
  
  
puts "nonzero? example 2:#{b.nonzero?()}\n\n"
  
puts "nonzero? example 3:#{c.nonzero?()}\n\n"

輸出:

nonzero? example 2:-0.20512110073058639999999999999999999999999999999999999999999999999999999999999999999999999999999E96

nonzero? example 3:-0.3E1



相關用法


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