Menu
Coddy logo textTech

The ROUND() Function

Part of the Fundamentals section of Coddy's SQL journey — lesson 26 of 72.

The ROUND() function is used to round a numeric value to a specified number of decimal places. To use the function follow this syntax:

ROUND(number, decimal_places)
  • number: The number you want to round
  • decimal_places: (Optional) The number of decimal places to round to
    • If omitted, rounds to the nearest whole number
    • If positive, rounds to that many decimal places
    • If negative, rounds to the left of the decimal point

For example, 

Basic rounding to whole numbers:

SELECT ROUND(3.7);
-- Returns 4

SELECT ROUND(3.3);
-- Returns 3

SELECT ROUND(3.5);  
-- Returns 4.0 (rounds up from .5)

Rounding to specific decimal places:

SELECT ROUND(3.14159, 2);
-- Returns 3.14

SELECT ROUND(3.14159, 1);
-- Returns 3.1

SELECT ROUND(3.14159, 0);
-- Returns 3.0

SELECT ROUND(3.145, 2);
-- Returns 3.15 (rounds up because the next digit is 5)

Note: When the digit after the last kept decimal place is 5 or greater, the last kept decimal rounds up.

Practical example with a table:

SELECT 
    product_name,
    ROUND(price, 2) as rounded_price
FROM products;

Cheat sheet

The ROUND() function rounds numeric values to a specified number of decimal places:

ROUND(number, decimal_places)
  • number: The number to round
  • decimal_places: (Optional) Number of decimal places
    • If omitted, rounds to whole number
    • If positive, rounds to that many decimal places
    • If negative, rounds to the left of decimal point

Examples:

SELECT ROUND(3.7);        -- Returns 4
SELECT ROUND(3.14159, 2); -- Returns 3.14
SELECT ROUND(3.14159, 0); -- Returns 3

In queries:

SELECT 
    product_name,
    ROUND(price, 2) as rounded_price
FROM products;

Try it yourself

This lesson doesn't include a code challenge.

quiz iconTest yourself

This lesson includes a short quiz. Start the lesson to answer it and track your progress.

All lessons in Fundamentals