ROUND

The ROUND function returns a number that is rounded to the specified number of places to the right or left of the decimal place.

Read syntax diagram
                                   .-,--0--------------------.      
>>-ROUND--(--numeric-expression-1--+-------------------------+--)-><
                                   '-,--numeric-expression-2-'      

The schema is SYSIBM.

numeric-expression-1
An expression that returns a value of any built-in numeric data type.

If expression-1 is a decimal floating-point data type, the DECFLOAT ROUNDING MODE will not be used. The rounding behavior of ROUND corresponds to a value of ROUND_HALF_UP. If you want a different rounding behavior, use the QUANTIZE function.

Start of changeThe argument can also be a character string or graphic string data type. The string input is implicitly cast to a numeric value of DECFLOAT(34).End of change

numeric-expression-2

Start of changeAn expression that returns a value that is a built-in numeric, character string or graphic string data type. If the value is not of type INTEGER, it is implicitly cast to INTEGER before evaluating the function.End of change

The absolute value of integer specifies the number of places to the right of the decimal point for the result if numeric-expression-2 is not negative. If numeric-expression-2 is negative, numeric-expression-1 is rounded to the sum of the absolute value of numeric-expression-2+1 number of places to the left of the decimal point.

If the absolute value of numeric-expression-2 is larger than the number of digits to the left of the decimal point, the result is 0. (For example, ROUND(748.58,-4) returns 0.)

If numeric-expression-1 is positive, a digit value of 5 is rounded to the next higher positive number. If numeric-expression-1 is negative, a digit value of 5 is rounded to the next lower negative number.

The result of the function has the same data type and length attribute as the first argument except that the precision is increased by one if the argument is DECIMAL and the precision is less than 31. For example, an argument with a data type of DECIMAL(5,2) results in DECIMAL(6,2). An argument with a data type of DECIMAL(31,2) results in DECIMAL(31,2).

The result can be null; if any argument is null, the result is the null value.

Example 1: Calculate the number '873.726' rounded to '2', '1', '0', '-1', and '-2' decimal places respectively.
   SELECT ROUND(873.726,2),
          ROUND(873.726,1),
          ROUND(873.726,0),
          ROUND(873.726,-1),
          ROUND(873.726,-2),
          ROUND(873.726,-3),
          ROUND(873.726,-4)
     FROM SYSIBM.SYSDUMMY1;
This example returns the values '0873.730', '0873.700', '0874.000', '0870.000', '0900.000', '1000.000', and '0000.000'.
Example 2: To demonstrate how numbers are rounded in positive and negative values, calculate the numbers '3.5', '3.1', '-3.1', '-3.5' rounded to '0' decimal places.
   SELECT ROUND(3.5,0),
          ROUND(3.1,0),
          ROUND(-3.1,0),
          ROUND(-3.5,0)
     FROM SYSIBM.SYSDUMMY1;
This example returns the values '04.0', '03.0', '-03.0', and '-04.0'. (Notice that in the positive value '3.5' is rounded up to the next higher number while in the negative value '-3.5' is rounded down to the next lower negative number.)