Round Function In Sql in SQL
? ROUND() Function in SQL
The ROUND() function in SQL is used to round a numeric value to a specified number of decimal places.
? Syntax:
ROUND(number, decimal_places)number: The numeric value to round.decimal_places: The number of digits after the decimal point.
? Example 1: Round to 2 decimal places
SELECT ROUND(123.4567, 2) AS rounded_value;Output:
| rounded_value |
|---|
| 123.46 |
? Example 2: Round to whole number
SELECT ROUND(123.89, 0) AS rounded_value;Output:
| rounded_value |
|---|
| 124 |
? Example 3: Round negative decimal places (to tens, hundreds)
SELECT ROUND(1234.567, -2) AS rounded_value;Output:
| rounded_value |
|---|
| 1200 |
? Differences in SQL Versions:
MySQL: Supports
ROUND(number, decimal_places)SQL Server: Same syntax
Oracle: Also supports
ROUND(date)to round dates (e.g., to nearest month)
? Use Cases:
Financial calculations (e.g., rounding prices or taxes)
Formatting results for display
Simplifying long decimal numbers
Want to explore CEIL(), FLOOR(), or TRUNC() for comparison?