Skip to content
Related Articles

Related Articles

Ruby Integer ceil function with example
  • Last Updated : 07 Jan, 2020

The ceil function in Ruby returns the smallest number greater than or equal to int with a precision of ndigits decimal digits. The default is considered to be 0. When the precision given is negative, the returned value is an integer with at least ndigits.abs trailing zeros. It returns self when ndigits positive.

Syntax: (number).ceil(ndigits)

Parameter: The function takes the integer whose ceil value is to be returned and a single parameter ndigits which specifies the precision to be returned.

Return Value: The function returns the smallest integer number greater than or equal to it.

Example #1:






# Ruby program of ceil function
  
# Initializing the numbers 
num1 = 10
num2 = 17
num3 = 17.5
num4 = 21.5
   
# Prints the ceil value
puts num1.ceil
puts num2.ceil(1)
puts num3.ceil(0)
puts num4.ceil(2)


Output:

10
17.0
18
21.5

Example #2:




# Ruby program of ceil function
  
# Initializing the numbers 
num1 = 13
num2 = -90
num3 = 90
num4 = 81.7
   
# Prints the ceil value
puts num1.ceil
puts num2.ceil(2)
puts num3.ceil(-1)
puts num4.ceil(0)


Output:

13
-90.0
90
82
My Personal Notes arrow_drop_up
Recommended Articles
Page :