红宝石 |数字分母()函数
denominator()是 Ruby 中的一个内置方法,它返回数字的分母。
Syntax: num1.denominator()
Parameters: The function needs a number whose denominator is returned.
Return Value: It returns itself only.
示例 1 :
# Ruby program for denominator() method in Matrix
# Initialize a number
num1 = 1.5
# Function used
num = num1.denominator()
# Prints denominator() of num
puts num
输出:
2
示例 2 :
# Ruby program for denominator() method in Matrix
# Initialize a number
num1 = 155
# Function used
num = num1.denominator()
# Prints denominator() of num
puts num
输出:
1