📜  红宝石 | BigDecimal ()函数

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

红宝石 | BigDecimal ()函数

BigDecimal#sign() :sign()是一个 BigDecimal 类方法,它将 Big Decimal 签名为最接近的整数。

示例 #1:

# Ruby code for BigDecimal.sign() method
  
# loading library
require 'bigdecimal'
  
# declaring bigdecimal
a = BigDecimal("10333")
  
# declaring bigdecimal
b = -BigDecimal("10")
  
# declaring bigdecimal
c = BigDecimal("565")
  
# sign() method
puts "BigDecimal example sign : #{a.sign()}\n\n"
  
puts "BigDecimal example sign : #{b.sign()}\n\n"
  
puts "BigDecimal example sign : #{c.sign()}\n\n"

输出 :

BigDecimal example sign : 2

BigDecimal example sign : -2

BigDecimal example sign : 2

示例 #2:

# Ruby code for BigDecimal.sign() method
  
# loading library
require 'bigdecimal'
  
# declaring bigdecimal
a = BigDecimal('43443')
  
# declaring bigdecimal
b = BigDecimal('10')
  
# declaring bigdecimal
c = BigDecimal('-3')
  
# sign() method
puts "BigDecimal example sign : #{a.sign()}\n\n"
  
puts "BigDecimal example sign : #{b.sign()}\n\n"
  
puts "BigDecimal example sign : #{c.sign()}\n\n"

输出 :

BigDecimal example sign : 2

BigDecimal example sign : 2

BigDecimal example sign : -2