红宝石 |数值 fdiv()函数
fdiv()是 Ruby 中的一个内置方法,它在执行浮点除法后返回结果。
Syntax: num1.fdiv(num2)
Parameters: The function needs two numbers whose float division is to be performed.
Return Value: It returns returns the float division.
示例 1 :
# Ruby program for fdiv() method in Numeric
# Initialize a number
num1 = 15
# Prints division of num1/4
puts num1.fdiv(4)
输出:
3.75
示例 2 :
# Ruby program for fdiv() method in Numeric
# Initialize a number
num1 = 20
# Prints division of num1/2
puts num1.fdiv(2)
输出:
10.0