MariaDB ROUND() Function
The MariaDB ROUND() function returns a number rounded to the specified number of decimal places. If decimal_places is a negative number, this function will make digits to the left of the decimal place 0 values.
Note: The behavior of the ROUND function can vary depending on the version of MariaDB.
Syntax
ROUND(number, decimal_places)
Parameters
number |
Required. Specify the number to round. |
decimal_places |
Optional. Specify the number of decimal places to round. This value must be a positive or negative integer. If this parameter is omitted, the function rounds the number to 0 decimal places. |
Return Value
Returns the rounded value of the number to specified decimal_places.
Example 1:
The example below shows the usage of ROUND() function.
SELECT ROUND(1234.5678, 0); Result: 1235 SELECT ROUND(1234.5678, 1); Result: 1234.6 SELECT ROUND(1234.5678, 2); Result: 1234.57 SELECT ROUND(1234.5678, 3); Result: 1234.568 SELECT ROUND(1234.5678, -1); Result: 1230 SELECT ROUND(1234.5678, -2); Result: 1200 SELECT ROUND(1234.5678); Result: 1235 SELECT ROUND(-1234.5678); Result: -1235
Example 2:
Consider a database table called Sample with the following records:
Data | x |
---|---|
Data 1 | -3.75567 |
Data 2 | -5.3867 |
Data 3 | 13.9804 |
Data 4 | 93.1601 |
Data 5 | 48.1322 |
The statement given below can be used to round the records of column x to 2 decimal places.
SELECT *, ROUND(x, 2) AS ROUND_Value FROM Sample;
This will produce the result as shown below:
Data | x | ROUND_Value |
---|---|---|
Data 1 | -3.75567 | -3.76 |
Data 2 | -5.3867 | -5.39 |
Data 3 | 13.9804 | 13.98 |
Data 4 | 93.1601 | 93.16 |
Data 5 | 48.1322 | 48.13 |
❮ MariaDB Functions