ROUND | Syntax: | ROUND(Number [, Decimals]) | Return value: | DECIMAL | Function type: | Numeric function | |
|
|
The ROUND() function rounds "Number" to "Decimals". Decimal places defaults to 0 if not specified.
Decimal places can be negative so that the digits to the left of the decimal point of "Number" become zero.
ROUND() returns NULL if the value of "Number" is NULL. |
Example 1: Rounding without decimals. |
|
select round(45.67) as result;
|
|
|
Example 2: Rounding with decimals. |
|
select round(45.67,1) as result;
|
|
|
Example 3: Rounding with negative decimals. |
|
select round(45.67,-1) as result;
|
|
|
Example 4: Rounding with negative decimals. |
|
select round(45.67,-2) as result;
|
|
|
Example 5: Rounding with negative decimals. |
|
select round(145.67,-2) as result;
|
|
|
The examples were created with the MyWAY SQL manager: |
How to use the ROUND() function in MySQL and MariaDB databases |
The ROUND() function in MySQL and MariaDB can be useful in various applications where numeric Values must be rounded to a specific number of decimal places:
When users are presented with numeric data, the values can be rounded to a specified number of decimal places for readability. The ROUND() function helps to format the values before displaying them.
When calculating average values of numeric data, the result can be rounded to a specified number of decimal places. This ensures that the average is consistent and easy to interpret.
In financial applications, it is often necessary to round monetary values to a specified number of decimal places to ensure accuracy and to comply with certain regulations or conventions.
When reporting or performing aggregations on numeric data, the resulting values may need to be rounded to the desired precision.
In data analysis tasks, rounding values can be useful to simplify data or reduce the level of detail. It can also be useful when comparing values or grouping data based on rounded values. |
|
Further MySQL und MariaDB SQL Numeric functions |
|