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 number num1 = - 19
num2 = - 18 . 97
num3 = 18 . 98
# Prints ceil() of num puts num1.ceil() puts num2.ceil() puts num3.ceil() |
Output:
-19 -18 19
Example 2:
Ruby
# Ruby program for ceil() method in Numeric # Initialize a number num1 = - 19 . 897
num2 = - 18 . 321
num3 = 190 . 23213
# Prints ceil() of num puts num1.ceil( 1 )
puts num2.ceil( 2 )
puts num3.ceil( 3 )
|
Output:
-19.8 -18.32 190.233