Number.ceiling
ceiling($precision = 0) -> number
Description
Round a fraction up. (i.e. toward positive infinity)
|--> |--> ----+----+----+----+----+----+----+--- -3 -2 -1 0 1 2 3
$num = 9.1 $num.ceiling() //= 10 $num = 3.8 $num.ceiling() //= 4 $num = -5.7 $num.ceiling() //= -5
Comparison of Rounding Methods
Method | Description | Example |
---|---|---|
floor | Round down (toward negative infinity) | 4.7 → 4 |
ceiling | Round up (toward positive infinity) | 2.3 → 3 |
toInt | Drop all digits after the decimal point | 7.33 → 7 |
round | Round to a given precision | 6.56 → 6.5 |
Precision
If $precision
is greater than zero, it will return a float with the given number of decimal places.
$num = 9.259 $num.ceiling(2) //= 9.26