Bird
Raised Fist0
MySQLquery~5 mins

ROUND, CEIL, FLOOR in MySQL

Choose your learning style10 modes available
Introduction
These functions help you change numbers to simpler forms. ROUND makes numbers closer to a chosen decimal place. CEIL rounds numbers up to the smallest whole number greater than or equal to it. FLOOR rounds numbers down to the largest whole number less than or equal to it.
When you want to show prices rounded to two decimal places.
When you need to count how many full boxes you need if you have some items left over.
When you want to ignore the decimal part and get the largest whole number less than or equal to a value.
When calculating age from birthdate and you want to round down to full years.
When you want to display a number without decimals for easier reading.
Syntax
MySQL
ROUND(number, decimals)
CEIL(number)
FLOOR(number)
ROUND can take two arguments: the number and how many decimals to keep. If decimals is missing, it rounds to the nearest whole number.
CEIL rounds up to the smallest whole number greater than or equal to the number.
FLOOR rounds down to the largest whole number less than or equal to the number.
Examples
Rounds 3.14159 to 2 decimal places, result is 3.14.
MySQL
SELECT ROUND(3.14159, 2);
Rounds 4.2 up to the next whole number, result is 5.
MySQL
SELECT CEIL(4.2);
Rounds 4.8 down to the previous whole number, result is 4.
MySQL
SELECT FLOOR(4.8);
Rounds 5.678 to the nearest whole number, result is 6.
MySQL
SELECT ROUND(5.678);
Sample Program
This query shows how ROUND, CEIL, and FLOOR work on the number 7.456.
MySQL
SELECT ROUND(7.456, 1) AS rounded_value,
       CEIL(7.456) AS ceiling_value,
       FLOOR(7.456) AS floor_value;
OutputSuccess
Important Notes
If you use ROUND without the second argument, it rounds to the nearest whole number.
CEIL and FLOOR always return whole numbers (integers).
These functions work well for money, measurements, or any time you want simpler numbers.
Summary
ROUND changes numbers to a chosen decimal place or whole number.
CEIL rounds numbers up to the smallest whole number greater than or equal to it.
FLOOR rounds numbers down to the largest whole number less than or equal to it.

Practice

(1/5)
1. Which MySQL function rounds a number to the nearest whole number or specified decimal place?
easy
A. CEIL
B. ROUND
C. FLOOR
D. TRUNCATE

Solution

  1. Step 1: Understand the function purpose

    ROUND changes a number to the nearest integer or decimal place, unlike CEIL or FLOOR which only round up or down.
  2. Step 2: Compare with other functions

    CEIL always rounds up, FLOOR always rounds down, TRUNCATE cuts decimals without rounding.
  3. Final Answer:

    ROUND -> Option B
  4. Quick Check:

    ROUND = nearest rounding [OK]
Hint: ROUND = nearest number, CEIL up, FLOOR down [OK]
Common Mistakes:
  • Confusing CEIL with ROUND
  • Thinking FLOOR rounds to nearest
  • Assuming TRUNCATE rounds
2. Which of the following is the correct syntax to round the number 3.14159 to 2 decimal places in MySQL?
easy
A. ROUND(3.14159, 2)
B. CEIL(3.14159, 2)
C. FLOOR(3.14159, 2)
D. ROUND(3.14159. 2)

Solution

  1. Step 1: Check function usage

    ROUND accepts two arguments: the number and the decimal places to round to.
  2. Step 2: Identify correct syntax

    ROUND(3.14159, 2) is correct; CEIL and FLOOR do not take decimal places, and ROUND(3.14159. 2) has a syntax error with a dot instead of a comma.
  3. Final Answer:

    ROUND(3.14159, 2) -> Option A
  4. Quick Check:

    ROUND(number, decimals) syntax [OK]
Hint: ROUND(number, decimals) uses comma, CEIL/FLOOR no decimals [OK]
Common Mistakes:
  • Using CEIL or FLOOR with decimal places
  • Using dot instead of comma between arguments
  • Missing second argument for ROUND
3. What is the result of the query: SELECT CEIL(4.2), FLOOR(4.8), ROUND(4.5);?
medium
A. 5, 4, 5
B. 4, 4, 4
C. 5, 5, 5
D. 4, 5, 4

Solution

  1. Step 1: Evaluate CEIL(4.2)

    CEIL rounds up to the next whole number, so CEIL(4.2) = 5.
  2. Step 2: Evaluate FLOOR(4.8) and ROUND(4.5)

    FLOOR rounds down, so FLOOR(4.8) = 4. ROUND rounds to nearest integer, 4.5 rounds up to 5.
  3. Final Answer:

    5, 4, 5 -> Option A
  4. Quick Check:

    CEIL=5, FLOOR=4, ROUND=5 [OK]
Hint: CEIL up, FLOOR down, ROUND nearest (0.5 rounds up) [OK]
Common Mistakes:
  • Thinking FLOOR(4.8) is 5
  • Rounding 4.5 down instead of up
  • Confusing CEIL and FLOOR
4. Identify the error in this query: SELECT CEIL(5.7, 1), FLOOR(3.2), ROUND(2.718);
medium
A. ROUND requires two arguments
B. FLOOR requires two arguments
C. CEIL does not accept two arguments
D. No error, query is correct

Solution

  1. Step 1: Check CEIL function arguments

    CEIL only accepts one argument (the number). Passing two arguments causes an error.
  2. Step 2: Verify FLOOR and ROUND usage

    FLOOR accepts one argument, ROUND can accept one or two arguments. Both FLOOR(3.2) and ROUND(2.718) are valid.
  3. Final Answer:

    CEIL does not accept two arguments -> Option C
  4. Quick Check:

    CEIL = 1 argument only [OK]
Hint: CEIL/FLOOR take 1 argument; ROUND can take 1 or 2 [OK]
Common Mistakes:
  • Passing two arguments to CEIL or FLOOR
  • Assuming ROUND always needs two arguments
  • Thinking query has no errors
5. You have a table prices with a column cost containing decimal values. You want to create a new column rounded_cost that rounds cost to the nearest integer but always rounds up if the decimal part is exactly 0.5. Which MySQL expression achieves this?
hard
A. ROUND(cost)
B. IF(cost - FLOOR(cost) = 0.5, FLOOR(cost), ROUND(cost))
C. CEIL(cost - 0.5)
D. CEIL(cost)

Solution

  1. Step 1: Understand rounding rules

    In MySQL, ROUND rounds to nearest integer; halfway cases (.5) round away from zero (up for positive numbers).
  2. Step 2: Select the correct expression

    CEIL(cost) always rounds up, so it rounds up when decimal part is exactly 0.5, fulfilling the requirement.
  3. Step 3: Analyze other options

    A rounds .5 up normally, but does not always round up if decimal is exactly 0.5 (it rounds to nearest). B rounds down for exactly .5, which is incorrect. D fails on .5 cases as CEIL(cost - 0.5) can round down.
  4. Final Answer:

    CEIL(cost) -> Option D
  5. Quick Check:

    CEIL(cost) always rounds up [OK]
Hint: CEIL(cost) always rounds up, including .5 cases [OK]
Common Mistakes:
  • Assuming ROUND always rounds .5 up as needed
  • Using conditional that rounds .5 down
  • CEIL(cost - 0.5) fails on .5 cases
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard