红宝石 | BigDecimal ()函数
BigDecimal#sign() :sign()是一个 BigDecimal 类方法,它将 Big Decimal 签名为最接近的整数。
Syntax: BigDecimal.sign()
Parameter: BigDecimal values
Return: signs the Big decimal to the nearest integer.
示例 #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