📜  Ruby Float next_float() 方法与示例

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

Ruby Float next_float() 方法与示例

Float next_float()是一个浮点类方法,它返回浮点数的下一个表示。

示例 #1:

# Ruby program for next_float() method
  
# Initializing value
a = 26.00/ 3
b = 8.0999
c = 3 + 105.003
  
# Printing Result
puts "Next Floating Point Number : #{a.next_float}\n\n"
puts "Next Floating Point Number : #{b.next_float}\n\n"
puts "Next Floating Point Number : #{c.next_float}\n\n"

输出 :

Next Floating Point Number : 8.666666666666668

Next Floating Point Number : 8.099900000000002

Next Floating Point Number : 108.00300000000001

示例 #2:

# Ruby program for next_float() method
  
# Initializing value
a = 26.00
b = 8.0
  
# Printing Result
puts "Next Floating Point Number : #{a.next_float}\n\n"
puts "Next Floating Point Number : #{b.next_float}\n\n"

输出 :

Next Floating Point Number : 26.000000000000004

Next Floating Point Number : 8.000000000000002