Ruby Float prev_float() method with example
Float prev_float() is a float class method which returns the previous representation of the floating point number.
Syntax: float.prev_float()
Parameter: float value to be passed
Return: Previous representation of the floating point number.
Example #1:
# Ruby code for prev_float() method # Initializing valuea = 26.00/ 3b = 8.0999c = 3 + 105.003 # Printing Resultputs "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" |
Output :
previous Floating Point Number : 8.666666666666664 previous Floating Point Number : 8.099899999999998 previous Floating Point Number : 108.00299999999999
Example #2:
# Ruby code for next_float() method # Initializing valuea = 26.00b = 8.0 # Printing resultputs "previous Floating Point Number : #{a.next_float}\n\n"puts "previous Floating Point Number : #{b.prev_float}\n\n" |
Output :
previous Floating Point Number : 26.000000000000004 previous Floating Point Number : 7.999999999999999




