ROUND() in SQL

Rounds a number to a specified number of decimal places or to the nearest integer.

Syntax

ROUND(number [, decimals])
Return type
NUMERIC (or equivalent numeric type in the respective DBMS

ROUND() Function Example

SELECT ROUND(123.4567, 2); 
-- Output: 123.46

What is ROUND() in SQL?

The ROUND() function in SQL is used to round a numeric value to a specified number of decimal places or to the nearest integer if no decimal places are provided. It is commonly used in financial calculations, statistical analysis, and data formatting where precision is required. The function takes two arguments: the number to be rounded and the number of decimal places. In SQL Server, an optional third parameter determines whether the value is rounded normally (default) or truncated. ROUND() is widely supported in databases like MySQL, PostgreSQL, and SQL Server, making it essential for ensuring consistent numerical precision in queries.

Parameters:

  • number: The numeric value to be rounded

  • decimals: (Optional) Number of decimal places to round to. Default is 0.

Example Use Cases:

-- Round prices to 2 decimal places

SELECT ROUND(price, 2) AS rounded_price FROM products; 
-- Output:
rounded_price
-------------
19.99
24.50
99.99
149.99
499.95

-- Round quantities to nearest whole number

SELECT ROUND(quantity) AS rounded_qty FROM inventory; 
-- Output:
rounded_qty
-----------
10
25
8
15
42

-- Round percentages to one decimal place 

SELECT ROUND(discount_percentage, 1) AS rounded_discount FROM offers;
-- Output:
rounded_discount
---------------
15.5
25.0
10.0
30.5
20.0

Notes:

  • Behavior: Rounds away from zero for values exactly halfway between two numbers (e.g., 2.5 rounds to 3)

  • Performance Considerations: Basic numeric operation, highly efficient

  • Version Info: Core numeric function available in all major DBMS

  • Deprecated/Recommended Alternatives: None

Error Handling:

  • Error: Returns NULL if input is NULL

  • Recommendation: Use COALESCE if NULL handling needed

Supported Databases:

DBMS
Function / Syntax
Example
Behavior with NULL
MySQL

ROUND(X,D)

ROUND(123.456, 2)

Returns NULL

PostgreSQL

ROUND(v numeric, s int)

ROUND(123.456, 2)

Returns NULL

SQL Server

ROUND(number, length)

ROUND(123.456, 2)

Returns NULL

SQLite

ROUND(X,Y)

ROUND(123.456, 2)

Returns NULL

BigQuery

ROUND(X[, N])

ROUND(123.456, 2)

Returns NULL

Snowflake

ROUND(number[, precision])

ROUND(123.456, 2)

Returns NULL

Athena

ROUND(X,D)

ROUND(123.456, 2)

Returns NULL

Related Functions:

One place for all your queries,
directly on your SQL editor