红宝石 |浮点分子()方法
Float numerator()是一个浮点类方法,它返回一个浮点值作为 p/q 形式的分子值。
Syntax:float.numerator()
Parameter: float value (p) for the p/q form. [Always positive]
Return: A machine-dependent result.
示例 #1:
# Ruby program for numerator() method
a = 2.0.numerator()
# Returning machine dependent result
puts "numerator : #{a}\n\n"
# Using as a numerator
puts "Division int/float : #{a.fdiv(4)}\n\n"
puts "Division float/float : #{a.fdiv(4.0)}\n\n"
输出 :
numerator : 2
Division int/float : 0.5
Division float/float : 0.5
示例 #2:
# Ruby program for numerator() method
# Initializing value
a = 0.numerator()
# returning machine dependent result
puts "numerator : #{a}\n\n"
puts "Division int/float : #{a.fdiv(4)}\n\n"
puts "Division float/float : #{a.fdiv(4.0)}\n\n"
输出 :
numerator : 0
Division int/float : 0.0
Division float/float : 0.0