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


Ruby Float prev_float()用法及代碼示例


浮點數prev_float()是一個浮點類方法,它返回浮點數的先前表示形式。

用法: float.prev_float()

參數:要傳遞的浮點值


返回:浮點數的先前表示形式。

範例1:

# Ruby code for prev_float() method 
  
# Initializing value 
a = 26.00/ 3
b = 8.0999
c = 3 + 105.003
  
# Printing Result 
puts "previous Floating Point Number:#{a.prev_float}\n\n"
puts "previous Floating Point Number:#{b.prev_float}\n\n"
puts "previous Floating Point Number:#{c.prev_float}\n\n"

輸出:

previous Floating Point Number:8.666666666666664

previous Floating Point Number:8.099899999999998

previous Floating Point Number:108.00299999999999

範例2:

# Ruby code for next_float() method 
  
# Initializing value 
a = 26.00
b = 8.0
  
# Printing result 
puts "previous Floating Point Number:#{a.next_float}\n\n"
puts "previous Floating Point Number:#{b.prev_float}\n\n"

輸出:

previous Floating Point Number:26.000000000000004

previous Floating Point Number:7.999999999999999


相關用法


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