Ruby | Numeric ceil() function
The ceil() is an inbuilt method in Ruby returns the smallest number which is greater than or equal to the given number by keeping a precision of n digits of the decimal part.
Syntax: num.ceil(n digits)
Parameters: The function needs a number and n digits to which the precision of decimal digits is kept. In case no n digits is passed it takes 0 to be the default value.
Return Value: It returns the smallest number which is greater than or equal to the given number by keeping a precision of n digits of the decimal part.
Example 1:
Ruby
# Ruby program for ceil() method in Numeric# Initialize a numbernum1 = -19num2 = -18.97num3 = 18.98# Prints ceil() of numputs num1.ceil()puts num2.ceil()puts num3.ceil() |
Output:
-19 -18 19
Example 2:
Ruby
# Ruby program for ceil() method in Numeric# Initialize a numbernum1 = -19.897num2 = -18.321num3 = 190.23213# Prints ceil() of numputs num1.ceil(1)puts num2.ceil(2)puts num3.ceil(3) |
Output:
-19.8 -18.32 190.233


