Ruby 整数 fdiv()函数与示例
Ruby 中的fdiv()函数返回两个数字相除后的浮点结果。
Syntax: (number1).fdiv(number2)
Parameter: The function needs two numbers number1 and number2, where number1 is the dividend and number2 is the divisor.
Return Value: The function returns the floating point division of two numbers.
示例 #1:
# Ruby program of Integer fdiv() function
# Initializing the numbers
num1 = 5
num2 = 2
num3 = 9
num4 = 3
# Prints the division
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 division
puts num1.fdiv(num2)
puts num3.fdiv(num4)
输出:
3.75
5.0