Syntax
ROUND(X)
ROUND(X,D)
Purpose
Returns a value that is rounded to the specified length or precision.
If only one argument is provided, the function returns the value of X rounded to the nearest integer. If two arguments are provided, the function returns the value of X rounded to D decimal places, using the standard rounding rules. If you want to round the value of X to the left of the decimal point, you can specify a negative value for D.
The return value is of the same type as the first argument (assuming it is an integer, double, or decimal). This means that for an integer argument, the result is also an integer (without a fractional part).
For exact-value numbers,
ROUND()uses the "round half up" rule: values with a fractional part of.5or greater are rounded up to the nearest integer, while values with a fractional part less than.5are rounded down to the nearest integer. (In other words, the rounding direction is away from zero on the number line.)For approximate-value numbers,
ROUND()follows the "round half to even" rule: values with any fractional part are 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
