红宝石 |有理 fdiv()函数
fdiv()是 Ruby 中的一个内置函数,通过执行除法返回浮点数。
Syntax: rat.fdiv(numeric)
Parameters: The function accepts a single parameter
Return Value: It returns float by performing division
示例 1 :
Ruby
# Ruby program for fdiv() method
# Initialize rational number
rat1 = Rational(7, -3)
# Prints the rational number
puts rat1.fdiv(2)
Ruby
# Ruby program for fdiv() method
# Initialize rational number
rat1 = Rational(7)
# Prints the rational number
puts rat1.fdiv(2)
输出:
-1.1666666666666667
示例 2 :
红宝石
# Ruby program for fdiv() method
# Initialize rational number
rat1 = Rational(7)
# Prints the rational number
puts rat1.fdiv(2)
输出:
3.5