ROUND function
Rounds a numeric value to a specified number of decimal places.
Syntax
ROUND(expression [, decimal_places])
Arguments
expression: A numeric expression to round.decimal_places: Optional. The number of decimal places to round to. Default is 0 (round to nearest integer). Can be negative to round to the left of the decimal point.
Returns
The rounded value. The return type matches the input type: - DOUBLE input → DOUBLE - DECIMAL input → DECIMAL
Special Values
ROUND(inf)returnsinfROUND(-inf)returns-infROUND(NaN)returnsNaNROUND(NULL)returnsNULL
Examples
-- Example 1: Round decimals to nearest integer
> SELECT ROUND(7.0), ROUND(7.3), ROUND(7.5), ROUND(7.7);
7.0, 7.0, 8.0, 8.0
> SELECT ROUND(-7.0), ROUND(-7.3), ROUND(-7.5), ROUND(-7.7);
-7.0, -7.0, -8.0, -8.0
-- Example 2: Round doubles
> SELECT ROUND(CAST(7.5 AS DOUBLE)), ROUND(CAST(-7.5 AS DOUBLE));
8, -8
-- Example 3: Round to specific decimal places
> SELECT ROUND(CAST(123.456 AS DOUBLE), 2);
123.46
-- Example 4: Negative decimal places (round to left of decimal)
> SELECT ROUND(CAST(123.456 AS DOUBLE), -2);
100
> SELECT ROUND(CAST(-123.456 AS DOUBLE), -2);
-100
-- Example 5: Special floating-point values
> SELECT ROUND(CAST('inf' AS DOUBLE)), ROUND(CAST('-inf' AS DOUBLE));
inf, -inf
> SELECT ROUND(CAST('NaN' AS DOUBLE));
NaN
-- Example 6: NULL handling
> SELECT ROUND(CAST(NULL AS DOUBLE));
NULL
See Also
ABS function - Absolute value