CodeBlanks Logo Icon CodeBlanks

CEIL and FLOOR

Round numbers up and down.

CEIL and FLOOR

CEIL rounds a number up, FLOOR rounds down. CEIL always returns an integer greater or equal.

SELECT CEIL(price) AS up, FLOOR(price) AS down FROM products;

This query returns the rounded-up and rounded-down price.

CEIL(price) AS up, FLOOR(price) AS down is selected from products.

CEIL and FLOOR — details

CEIL(4.2) = 5, FLOOR(4.8) = 4. For negative numbers CEIL goes toward zero, FLOOR away from zero.

Practice CEIL and FLOOR

Select the ceiling of price aliased as up from products.

Starter code

query.sql
-- ceiling
SELECT
FROM products

Sample solution

query.sql
SELECT CEIL(price) AS up
FROM products

Expected output

up
5
13

Questions and answers

Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.

1 Round down

Question
SELECT ____(price) FROM products;
Answer
SELECT FLOOR(price) FROM products;

Explanation: FLOOR always rounds a number down to the nearest whole number.

2 What is CEIL(3.1)?

  • 3
  • 3.5
  • 4 Correct answer
  • 3.1

Explanation: CEIL always rounds up.

3 CEIL and FLOOR: match the terms

Term Meaning
CEIL up
FLOOR down
ROUND round
ABS absolute

All lessons in Beginner