📜  Ruby Float denominator() 方法与示例

📅  最后修改于: 2022-05-13 01:55:44.113000             🧑  作者: Mango

Ruby Float denominator() 方法与示例

Float#denominator() : denominator()是一个浮点类方法,它返回一个浮点值作为 p/q 形式的分母值。

示例 #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