All Products
Search
Document Center

MaxCompute:ROUND

Last Updated:Dec 04, 2025

The ROUND function rounds the number number to a specified decimal place.

Syntax

DOUBLE|DECIMAL ROUND(DOUBLE|DECIMAL <number>[, BIGINT <decimal_places>])

-- Standard example.
-- Returns 125.32.
SELECT ROUND(125.315, 2);

Parameters

  • number: Required. A value of the DOUBLE or DECIMAL type. If the input is a STRING or BIGINT value, it is implicitly converted to the DOUBLE type.

  • decimal_places: Optional. A BIGINT constant that specifies the decimal place to which the number is rounded. If you omit this parameter, the number is rounded to the nearest integer. The default value is 0.

    Note

    The value of decimal_places can be negative. A negative value indicates rounding to the left of the decimal point. The decimal part of the return value is 0. If the absolute value of the negative value is greater than or equal to the number of digits in the integer part of number, the function returns 0.0.

Return value

Returns a value of the DOUBLE or DECIMAL type. The following rules apply:

  • If number is a DOUBLE or DECIMAL type, a value of the corresponding type is returned.

    Note

    When number is a DOUBLE type, the result of the ROUND function may have a precision drift because the DOUBLE type cannot guarantee precision. For more information, see ROUND function precision issues.

  • If number is a STRING or BIGINT type, a value of the DOUBLE type is returned.

  • If decimal_places is not of the BIGINT type, an error is returned.

  • If number or decimal_places is NULL, NULL is returned.

Examples

-- Returns 125.0.
SELECT ROUND(125.315);

-- Returns 125.3.
SELECT ROUND(125.315, 1);

-- Returns 125.32.
SELECT ROUND(125.315, 2);

-- Returns 125.315.
SELECT ROUND(125.315, 3);

-- Returns -125.32.
SELECT ROUND(-125.315, 2);

-- Round to the hundreds place.
-- Returns 100.0.
SELECT ROUND(123.345, -2);

-- Returns NULL.
SELECT ROUND(NULL);

-- The specified precision exceeds the original number of decimal places. The original value is returned.
-- Returns 123.345.
SELECT ROUND(123.345, 4);

-- Round to the ten thousands place. The value is not large enough, so 0 is returned.
-- Returns 0.0.
SELECT ROUND(123.345, -4);

Related functions

ROUND is a mathematical function. For more information about data computation and conversion functions, see Mathematical functions.