MariaDB ROUND() Function
In MariaDB, ROUND() is a built-in numeric function that rounds a given numeric parameter to a given decimal places.
If you need to truncate decimal places by digits, use the TRUNCATE() function.
If you need to return the integer part of a number, use FLOOR(), CEIL(), or CEILING().
MariaDB ROUND() Syntax
Here is the syntax of the MariaDB ROUND() function:
ROUND(x[, d])
Parameters
x-
Required. The numbers being processed.
d-
Optional. The number of decimal places to keep. The default value is 0.
If you provide the wrong number of parameters, MariaDB will report an error: ERROR 1582 (42000): Incorrect parameter count in the call to native function 'ROUND'.
Return value
The MariaDB ROUND() function rounds the given number to the given number of decimal places.
If d is greater than equal to x the number of decimal places, returns the original number.
If d is less than the decimal places of x, returns after rounding to d decimal places.
If d is negative, the ROUND() function will replace d integers with 0 from the dot back forward.
If any parameter is NULL, the ROUND() function will return NULL.
MariaDB ROUND() Examples
This statement shows the basic usage of the MariaDB ROUND() function:
SELECT
ROUND(123.45678),
ROUND(123.45678, 0),
ROUND(123.45678, 1),
ROUND(123.45678, 2),
ROUND(123.45678, 4),
ROUND(123.45678, 5),
ROUND(123.45678, 6),
ROUND(123.45678, -1),
ROUND(123.45678, -2),
ROUND(123.45678, NULL)\G
Output:
ROUND(123.45678): 123
ROUND(123.45678, 0): 123
ROUND(123.45678, 1): 123.5
ROUND(123.45678, 2): 123.46
ROUND(123.45678, 4): 123.4568
ROUND(123.45678, 5): 123.45678
ROUND(123.45678, 6): 123.456780
ROUND(123.45678, -1): 120
ROUND(123.45678, -2): 100
ROUND(123.45678, NULL): NULLConclusion
In MariaDB, ROUND() is a built-in numeric function that rounds a given numeric parameter to a given decimal places.