红宝石 | BigDecimal 修复类值
BigDecimal#fix() : fix()是一个 BigDecimal 类方法,它返回 BigDecimal 值的整数值。
Syntax: BigDecimal.fix()
Parameter: BigDecimal values to find the integer value
Return: integer value for the BigDecimal value
代码 #1:fix() 方法的示例
# Ruby code for fix() method
# loading BigDecimal
require 'bigdecimal'
# declaring BigDecimal
b = -BigDecimal("10")
puts "fix example 2 : #{b.fix()}\n\n"
输出 :
fix example 2 : -0.1E2
代码 #2:fix() 方法的示例
# Ruby code for fix() method
# loading BigDecimal
require 'bigdecimal'
# declaring BigDecimal
b = BigDecimal('10')-(22 ** 7.1) ** 10
# declaring BigDecimal
c = BigDecimal('-3')
puts "fix example 2 : #{b.fix()}\n\n"
puts "fix example 3 : #{c.fix()}\n\n"
输出 :
fix example 2 : -0.20512110073058639999999999999999999999999999999999999999999999999999999999999999999999999999999E96
fix example 3 : -0.3E1