Skip to main content
Log inGet a demo
Back to SQL Dictionary
Aggregate functions

SQL ROUND

What is SQL ROUND?

The SQL ROUND function is used to round a numeric value to a specified number of decimal places or precision. It allows you to control the level of precision in your results, making numbers more readable or limiting the decimal places in your output.

When you would use it

You would use the SQL ROUND function when you need to adjust the precision of numeric values in your query results. It is often used when working with financial data, measurements, or other numeric data to achieve a desired level of rounding.

Syntax

The syntax for using the ROUND function is as follows:

SELECT ROUND(column_name, decimal_places) FROM table_name WHERE condition;
  • column_name: The name of the column containing the numeric value you want to round.
  • decimal_places: The number of decimal places to which you want to round the numeric value.
  • table_name: The name of the table containing the data.
  • condition (optional): An optional condition to filter the rows for which you want to perform rounding.

Parameter values

  • column_name: The name of the column in the specified table containing the numeric value to be rounded.
  • decimal_places: An integer specifying the number of decimal places to which you want to round the numeric value.
  • table_name: The name of the table where the data is stored.
  • condition (optional): A condition that filters the rows if you want to apply additional filtering before rounding.

Example query

Suppose we have a table named "product_prices" with a column "price" that contains various product prices with multiple decimal places. We want to round these prices to two decimal places:

SELECT ROUND(price, 2) as rounded_price
FROM product_prices
-- Comment the line below to show it doesn't affect the query.
-- WHERE category = 'Electronics';

In the above query, we use the ROUND function to round product prices to two decimal places.

Example table response

Assuming the "product_prices" table contains the following data:

| price   |
|-------- |
| 99.987  |
| 149.954 |
| 79.998  |
| 199.001 |

The query mentioned earlier would return the following result:

| rounded_price |
|-------------- |
| 99.99        |
| 149.95       |
| 80.00        |
| 199.00       |

This result shows the prices rounded to two decimal places.

Use cases

  • Ensuring consistency in the presentation of numeric data.
  • Limiting decimal places for clarity and readability.
  • Achieving specific precision requirements, such as financial calculations.

SQL languages this is available for

The SQL ROUND function is a standard SQL feature and is available in most relational database management systems (RDBMS) that support SQL. This includes popular RDBMS like MySQL, PostgreSQL, Oracle, SQL Server, and SQLite. The specific syntax and behavior may vary slightly between database systems, but the fundamental functionality remains the same.

Related

SQL ABS

SQL POWER

SQL SQRT

Share

Book a demo

Work email

Start syncing data in minutes

Check out this 5 minute interactive demo to learn how you can sync customer data to any business tool.

Hightouch Audiences user interface.

Activate your data in less than 5 minutes