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


Ruby Integer fdiv()用法及代碼示例

Ruby中的fdiv()函數將兩個數字相除後返回浮點結果。

用法:(number1).fdiv(number2)

參數:該函數需要兩個數字number1和number2,其中number1是被除數,number2是除數。


返回值:該函數返回兩個數字的浮點除法。

範例1:

# Ruby program of Integer fdiv() function 
  
# Initializing the numbers  
num1 = 5
num2 = 2
   
num3 = 9
num4 = 3 
   
# Prints the divison  
puts num1.fdiv(num2) 
puts num3.fdiv(num4)

輸出

2.5
3.0

範例2:

# Ruby program of Integer fdiv() function 
  
# Initializing the numbers  
num1 = 15
num2 = 4
   
num3 = 10
num4 = 2
   
# Prints the integer divison  
puts num1.fdiv(num2) 
puts num3.fdiv(num4)

輸出

3.75
5.0


相關用法


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