ceiling()
ceiling(x) Returns:
numeric · Updated March 13, 2026 · Base Functions math rounding numeric ceiling base
The ceiling() function rounds numeric values up to the nearest integer (toward positive infinity). It is useful when you need a safe upper bound for pagination, batching, sampling, or bucket calculations.
Syntax
ceiling(x)
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
x | numeric | required | A numeric vector or scalar to round up |
Examples
Basic usage
# Round up positive numbers
ceiling(3.14)
# [1] 4
ceiling(3.0)
# [1] 3
ceiling(0.1)
# [1] 1
Negative numbers
# Round up negative numbers (toward zero)
ceiling(-2.7)
# [1] -2
ceiling(-0.1)
# [1] 0
Working with vectors
x <- c(1.1, 2.5, 3.9, -1.1, -2.5)
ceiling(x)
# [1] 2 3 4 -1 -2
Common Patterns
Pagination
# Number of pages needed
items <- 57
per_page <- 10
ceiling(items / per_page)
# [1] 6
Price calculations
# Round prices up to nearest dollar
prices <- c(9.99, 19.50, 29.01, 100.00)
ceiling(prices)
# [1] 10 20 30 100
Array indexing
# Get minimum sample size
n <- 100
sample_frac <- 0.03
ceiling(n * sample_frac)
# [1] 3