In MySQL, the CEILING()
function allows you to round a number up to the nearest integer. More specifically, it returns the smallest integer not less than its argument.
You can also use the CEIL()
function, which is a synonym for CEILING()
.
Syntax
The syntax goes like this:
CEILING(X)
For exact-value numeric arguments, the return value has an exact-value numeric type. For string or floating-point arguments, the return value has a floating-point type.
Example 1 – Positive Values
Here’s an example of providing a positive value as the argument.
SELECT CEILING(1.87) Result;
Result:
+--------+ | Result | +--------+ | 2 | +--------+
In this case, 2
is the smallest integer not less than 1.87
.
Here’s another example, this time with a larger value.
SELECT CEILING(200.87) Result;
Result:
+--------+ | Result | +--------+ | 201 | +--------+
Example 2 – Negative Values
Here’s an example using a negative value.
SELECT CEILING(-1.87) Result;
Result:
+--------+ | Result | +--------+ | -1 | +--------+
In this case, -1
is the smallest integer not less than -1.87
.
Here’s another example.
SELECT CEILING(-200.87) Result;
Result:
+--------+ | Result | +--------+ | -200 | +--------+
The CEIL() Function
The CEIL()
function is a synonym for the CEILING()
function. Therefore you can replace all of the above examples with CEIL()
instead.
For example:
SELECT CEIL(1.87) Result;
Result:
+--------+ | Result | +--------+ | 2 | +--------+
Rounding Down – FLOOR()
If you prefer to round down to the nearest integer, use the FLOOR()
function instead.