Declaration
ROUND(X)
ROUND(X,D)
Description
Returns a number rounded to the specified length or precision.
The return parameter X is the closest approximate integer. When two parameters are provided, X is returned with D decimal places, rounded to the nearest whole number. To retain D decimal places before the decimal point of X, set D to a negative value.
The return value has the same type as the first argument (assuming it is an integer, double-precision number, or decimal). This means that for an integer parameter, the result is also an integer (without a fractional part).
For exact numbers, the
ROUND()function follows the "rounding" or "round to nearest" rule: for a value with a fractional part of.5or greater, it rounds up to the nearest whole number for positive numbers and down to the nearest whole number for negative numbers (in other words, the rounding direction is away from zero on the number line). For a value with a fractional part less than.5, it rounds down to the next lower whole number for positive numbers and down to the nearest whole number for negative numbers.For approximate numbers, the
ROUND()function follows the rule of "round up for numbers greater than or equal to 5, round down for numbers less than 5, and round to the nearest even number for numbers exactly equal to 5". That is, a value with any fractional part is rounded to the nearest even integer.
Examples
obclient> SELECT ROUND(2.15,2);
+---------------+
| ROUND(2.15,2) |
+---------------+
| 2.15 |
+---------------+
1 row in set
obclient> SELECT ROUND(2555e-2,1);
+------------------+
| ROUND(2555e-2,1) |
+------------------+
| 25.6 |
+------------------+
1 row in set
obclient> SELECT ROUND(25e-1), ROUND(25.3e-1), ROUND(35e-1);
+--------------+----------------+--------------+
| ROUND(25e-1) | ROUND(25.3e-1) | ROUND(35e-1) |
+--------------+----------------+--------------+
| 2 | 3 | 4 |
+--------------+----------------+--------------+
1 row in set