Skip to content

Maintenance Ruby 3.3 gets fixes, but no new features. Switch to Ruby 4.0 →

instance method

Integer#ceil

ceil(ndigits = 0) → integer

Returns the smallest number greater than or equal to self with a precision of ndigits decimal digits.

When the precision is negative, the returned value is an integer with at least ndigits.abs trailing zeros:

Example
555.ceil(-1)  # => 560
555.ceil(-2)  # => 600
-555.ceil(-2) # => -500
555.ceil(-3)  # => 1000

Returns self when ndigits is zero or positive.

Example
555.ceil     # => 555
555.ceil(50) # => 555

Related: Integer#floor.

See also #bit_length #ceildiv #anybits? #chr also in 4.1 · 4.0 · 3.4 · 3.2 · 3.1 · 3.0