ROUND CEIL FLOOR
In this page:
Rounding Numbers with ROUND
ROUND adjusts a decimal value to the nearest whole number by default, or to a specific number of decimal places if you pass a second argument, making it the general-purpose rounding tool for prices, averages, and ratings.
Example: Rounding Numbers with ROUND
SELECT ROUND(4.567) AS whole, ROUND(4.567, 1) AS one_decimal;
Rounding Up with CEIL
CEIL always rounds a number up to the next integer, even if the decimal portion is tiny — 2.01 becomes 3. This is useful whenever you need a guaranteed minimum, like calculating how many full boxes are needed to ship a partial quantity of items.
Example: Rounding Up with CEIL
SELECT CEIL(2.01) AS boxes_needed;
Rounding Down with FLOOR
FLOOR always rounds down to the next integer regardless of how close the decimal is to rounding up, which fits situations like calculating completed full hours of billing time where a partial hour shouldn't count.
Example: Rounding Down with FLOOR
SELECT FLOOR(3.9) AS full_hours;
Negative Decimal Places with ROUND
ROUND accepts negative numbers for its decimal-place argument, which rounds to the nearest ten, hundred, or thousand instead of fractional digits — handy for rounding sales figures to the nearest thousand for a summary report.
Example: Negative Decimal Places with ROUND
SELECT ROUND(45678, -3) AS rounded_to_thousand;
Using Math Functions in Tables
These functions work directly on table columns inside a SELECT statement, so you can present clean, rounded prices or ratings to users without ever changing the precise values actually stored in the database.
Example: Using Math Functions in Tables
CREATE TABLE products (id INT, price DECIMAL(10,4));
INSERT INTO products VALUES (1, 19.9567);
SELECT id, ROUND(price, 2) AS display_price FROM products;
Chapter Quiz — Complete all 6 topics to unlock
0/6 topics done
Complete these topics first: