📜  Ruby Float fdiv() 方法与示例

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

Ruby Float fdiv() 方法与示例

Float fdiv()是一个浮点类方法,它返回 p/q 形式的除法值。

示例 #1:

# Ruby program for fdiv() method
  
# Initializing value
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 fdiv() method
  
# Initializing value
a = 0.numerator()
  
# Printing 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