Skip to main content
Version: V1.0.0

ROUND

Syntax

ROUND(X)
ROUND(X,D)

Description

Returns a value rounded to the specified length or precision.

Returns the value of parameter X rounded to the nearest integer. If two parameters are specified, it returns the value of X rounded to D decimal places, with the Dth decimal place rounded to the nearest value. If you want to round the value of X to the left of the decimal point, set D to a negative value.

The return value has the same type as the first parameter (assuming it is an integer, double, or decimal). This means that for an integer parameter, the result is also an integer (without a decimal part).

  • For exact values, ROUND() uses the "round to the nearest" rule: a value with a fractional part of .5 or greater is rounded to the nearest integer in the direction away from zero. A value with a fractional part less than .5 is rounded to the nearest integer in the direction toward zero.

  • For approximate values, ROUND() follows the "round half up" rule: a value with any fractional part is rounded to the nearest even integer.

Examples

SELECT ROUND(2.15,2);
+---------------+
| ROUND(2.15,2) |
+---------------+
| 2.15 |
+---------------+
1 row in set (0.001 sec)

SELECT ROUND(2555e-2,1);
+------------------+
| ROUND(2555e-2,1) |
+------------------+
| 25.6 |
+------------------+
1 row in set (0.001 sec)

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