红宝石 |数值 numerator()函数
numerator()是 Ruby 中的一个内置方法,它返回分子。
Syntax: num.numerator()
Parameters: The function needs a number which is to be checked.
Return Value: It returns self or nil.
示例 1 :
# Ruby program for numerator()
# method in Numeric
# Initialize a number
num1 = 3.5
# Prints the numerator
puts num1.numerator()
输出:
12
示例 2 :
# Ruby program for numerator()
# method in Numeric
# Initialize a number
num1 = 1.5
# Prints the numerator
puts num1.numerator()
输出:
3