Ruby Float prev_float()方法及示例
Float prev_float()是一个float类方法,用于返回浮点数的前一个表示。
语法: float.prev_float()
参数: 要传递的浮点数
返回浮点数的上一个表示法。
例子 #1 :
# Ruby code for prev_float() method
# Initializing value
a = 26.00/ 3
b = 8.0999
c = 3 + 105.003
# Printing Result
puts "previous Floating Point Number : #{a.prev_float}\n\n"
puts "previous Floating Point Number : #{b.prev_float}\n\n"
puts "previous Floating Point Number : #{c.prev_float}\n\n"
输出:
previous Floating Point Number : 8.666666666666664
previous Floating Point Number : 8.099899999999998
previous Floating Point Number : 108.00299999999999
例子#2 。
# Ruby code for next_float() method
# Initializing value
a = 26.00
b = 8.0
# Printing result
puts "previous Floating Point Number : #{a.next_float}\n\n"
puts "previous Floating Point Number : #{b.prev_float}\n\n"
输出:
previous Floating Point Number : 26.000000000000004
previous Floating Point Number : 7.999999999999999