Syntax
ROUND(X)
ROUND(X,D)
Purpose
You can call this function to round a value to the specified length or precision.
If you specify X, the function rounds it to the nearest integer. If you specify two arguments, the function rounds X to D places to the right of the decimal point, and the Dth digit is rounded off. 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 an exact-value number,
ROUND()rounds it based on 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 or 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 an approximate-value number,
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 (0.00 sec)
obclient> SELECT ROUND(2555e-2,1);
+------------------+
ROUND(2555e-2,1)
+------------------+
25.6
+------------------+
1 row in set (0.01 sec)
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 (0.00 sec)