📜  红宝石 | BigDecimal 零?()函数

📅  最后修改于: 2022-05-13 01:55:44.982000             🧑  作者: Mango

红宝石 | BigDecimal 零?()函数

BigDecimal#zero?() : zero?()是一个 BigDecimal 类方法,用于检查 Big Decimal 值是否为零。

示例 #1:

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

输出 :

BigDecimal a zero? method : false

BigDecimal b zero? method : false

BigDecimal c zero? method : false

示例 #2:

# Ruby code for BigDecimal.zero?() 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('0')
  
# zero?() method
puts "BigDecimal a zero? method : #{a.zero?()}\n\n"
  
puts "BigDecimal b zero? method : #{b.zero?()}\n\n"
  
puts "BigDecimal c zero? method : #{c.zero?()}\n\n"

输出 :

BigDecimal a zero? method : false

BigDecimal b zero? method : false

BigDecimal c zero? method : true