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


Ruby BigDecimal floor用法及代碼示例


BigDecimal#floor():floor()是BigDecimal類方法,它返回傳遞的BigDecimal值的下限值。

用法: BigDecimal.floor()

參數:
-BigDecimal值,以獲取其底值
-十進製數字(默認= 0)


返回:
-最小數字> =到BigDecimal,精度為n位小數點。
-對於-ve精度:整數,至少n位數字。abs尾隨零。
-對於+ ve精度:BigDecimaling點數。

代碼#1:floor()方法示例

# Ruby code for floor() method 
  
# loading BigDecimal 
require 'bigdecimal'
  
# declaring BigDecimal 
a = 42.1**13
  
# declaring BigDecimal 
b = -BigDecimal("10") 
  
# declaring BigDecimal 
c = -(22 ** 7.1) * 10
  
# floor value of a 
puts "floor value of a:#{a.floor}\n\n"
  
# floor value of b 
puts "floor value of b:#{b.floor}\n\n"
  
# floor value of c 
puts "floor value of c:#{c.floor}\n\n"

輸出:

floor value of a:1305170490200643862528

floor value of b:-10

floor value of c:-33978252068

代碼2:floor()方法示例

# Ruby code for floor() method 
  
# loading BigDecimal 
require 'bigdecimal'
  
# declaring BigDecimal 
a = 12**12 - 27
  
# declaring BigDecimal 
b = BigDecimal('10')-(22 ** 7.1) ** 10
  
# declaring BigDecimal 
c = BigDecimal('-3') 
  
  
# floor value of a 
puts "floor value of a:#{a.floor}\n\n"
  
# floor value of b 
puts "floor value of b:#{b.floor}\n\n"
  
# floor value of c 
puts "floor value of c:#{c.floor}\n\n"

輸出:

floor value of a:8916100448229

floor value of b:-205121100730586399999999999999999999999999999999999999999999999999999999999999999999999999999990

floor value of c:-3



相關用法


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