Back to Library

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:

SIGN()

Returns the sign of a number: -1 for negative numbers, 0 for zero, and 1 for positive numbers.

Returns the sign of a number: -1 for negative numbers, 0 for zero, and 1 for positive numbers.

Returns the sign of a number: -1 for negative numbers, 0 for zero, and 1 for positive numbers.

Returns the sign of a number: -1 for negative numbers, 0 for zero, and 1 for positive numbers.

ABS()

Returns the absolute (positive) value of a number by removing the negative sign if present.

Returns the absolute (positive) value of a number by removing the negative sign if present.

Returns the absolute (positive) value of a number by removing the negative sign if present.

Returns the absolute (positive) value of a number by removing the negative sign if present.

RAND()/RANDOM()

Generates a random number. Without parameters, returns a floating-point number between 0 (inclusive) and 1 (exclusive). Some DBMS allow seeding for reproducible results.

Generates a random number. Without parameters, returns a floating-point number between 0 (inclusive) and 1 (exclusive). Some DBMS allow seeding for reproducible results.

Generates a random number. Without parameters, returns a floating-point number between 0 (inclusive) and 1 (exclusive). Some DBMS allow seeding for reproducible results.

Generates a random number. Without parameters, returns a floating-point number between 0 (inclusive) and 1 (exclusive). Some DBMS allow seeding for reproducible results.

MOD()

Returns the remainder after dividing one number by another. Also available as % operator in many databases.

Returns the remainder after dividing one number by another. Also available as % operator in many databases.

Returns the remainder after dividing one number by another. Also available as % operator in many databases.

Returns the remainder after dividing one number by another. Also available as % operator in many databases.

SQRT()

Returns the square root of a non-negative number. The square root is the value that, when multiplied by itself, gives the number.

Returns the square root of a non-negative number. The square root is the value that, when multiplied by itself, gives the number.

Returns the square root of a non-negative number. The square root is the value that, when multiplied by itself, gives the number.

Returns the square root of a non-negative number. The square root is the value that, when multiplied by itself, gives the number.

POWER()

Returns the result of raising a base number to a specified power (exponent). Also written as POW() in some databases.

Returns the result of raising a base number to a specified power (exponent). Also written as POW() in some databases.

Returns the result of raising a base number to a specified power (exponent). Also written as POW() in some databases.

Returns the result of raising a base number to a specified power (exponent). Also written as POW() in some databases.

ROUND()

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

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

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

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

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