Ruby Float next_float() method with example
Last Updated :
07 Jan, 2020
Float next_float() is a float class method which returns the next representation of the floating point number.
Syntax: float.next_float()
Parameter: float value to be passed
Return: Next representation of the floating point number.
Example #1:
a = 26 . 00 / 3
b = 8 . 0999
c = 3 + 105 . 003
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"
|
Output :
Next Floating Point Number : 8.666666666666668
Next Floating Point Number : 8.099900000000002
Next Floating Point Number : 108.00300000000001
Example #2:
a = 26 . 00
b = 8 . 0
puts "Next Floating Point Number : #{a.next_float}\n\n"
puts "Next Floating Point Number : #{b.next_float}\n\n"
|
Output :
Next Floating Point Number : 26.000000000000004
Next Floating Point Number : 8.000000000000002
Share your thoughts in the comments
Please Login to comment...