Ruby Float denominator() 方法与示例
Float#denominator() : denominator()是一个浮点类方法,它返回一个浮点值作为 p/q 形式的分母值。
Syntax: float.denominator()
Parameter: float value (q) for the p/q form. [Always positive]
Return: A machine-dependent result.
示例 #1:
# Ruby code for denominator() method
# Initialize value
a = 2.5.denominator()
# Printing result
puts "denominator : #{a}\n\n"
puts "Division int/float : #{4.fdiv(a)}\n\n"
puts "Division float/float : #{4.0.fdiv(a)}\n\n"
输出 :
denominator : 2
Division int/float : 2.0
Division float/float : 2.0
示例 #2:
# Ruby code for denominator() method
# Initialize value
a = 0.denominator()
# returning machine dependent result
puts "denominator : #{a}\n\n"
puts "Division int/float : #{4.fdiv(a)}\n\n"
puts "Division float/float : #{4.0.fdiv(a)}\n\n"
输出 :
denominator : 1
Division int/float : 4.0
Division float/float : 4.0