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(ndigits)

Parameters: The function needs a number and ndigits to which the precision of decimal digits is kept. In case no ndigits 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:

filter_none

edit
close

play_arrow

link
brightness_4
code

# Ruby program for ceil() method in Matrix
  
# Initialize a number 
num1 = -19
  
num2 = -18.97
  
num3 = 18.98
  
  
# Prints ceil() of num
puts  num1.ceil() 
puts  num2.ceil() 
puts  num3.ceil() 

chevron_right


Output:

-19
-18
19

Example 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

# Ruby program for ceil() method in Matrix
  
# 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

chevron_right


Output:

-19.8
-18.32
190.233


My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.