Syntax
ROUND(X)
ROUND(X,D)
Purpose
ROUND() rounds a value to the specified length or precision.
The returned value X approximates the nearest integer. Given two parameters, the returned value X is rounded off to D places to the right of the decimal point. To reserve X to D places to the left of the decimal point, set D to negative.
The return value is of the same type as that of the first independent variable (assuming that it is an integer, double-precision floating-point number, or decimal). This means that for an integer parameter, the result is also an integer (no fractional part).
For exact-value numbers,
ROUND()complies with the rule of "round half away from zero" or "round toward nearest". For a value whose fractional part is0.5or greater than0.5, the value is rounded up to the nearest integer if it is positive and rounded down to the nearest integer if it is negative. In other words, the value is rounded away from zero. For a value whose fractional part is less than0.5, the value is rounded down to the nearest integer if it is positive and rounded up to the nearest integer if it is negative.For approximate-value numbers,
ROUND()complies with the rule of "round to nearest even". This means that a value whose fractional part is exactly halfway between two integers 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