ROUND
functionsupportedCore SQL functionsReturns rounded values for input_expr.
Syntax
supportedpartialnot supportednot scored
ROUND( <input_expr> [ , <scale_expr> [ , '<rounding_mode>' ] ] )
ROUND( EXPR => <input_expr> ,
SCALE => <scale_expr>
[ , ROUNDING_MODE => '<rounding_mode>' ] )
Parameters
| Name | Required | Description |
|---|---|---|
input_expr OR EXPR => input_expr | required | The value or expression to operate on. The data type must be one of the numeric data types, such as DECFLOAT, FLOAT, or NUMBER. If you specify the EXPR => named argument, you must also specify the SCALE => named argument. |
scale_expr OR SCALE => scale_expr | optional | The number of digits the output includes after the decimal point. The default scale_expr is zero, meaning that the function removes all digits after the decimal point. For information about negative numbers, see Usage notes. If you specify the SCALE => named argument, you must specify EXPR => as the preceding named argument. |
'rounding_mode' OR ROUNDING_MODE => 'rounding_mode' | optional | The rounding mode to use. You can specify one of the following values: HALF_AWAY_FROM_ZERO. This mode rounds the value half away from zero. HALF_TO_EVEN. This mode rounds the value half to even. Default: HALF_AWAY_FROM_ZERO If you specify the ROUNDING_MODE => named argument, you must specify both EXPR => and SCALE => as preceding named arguments. Note If you specify either value for the rounding_mode argument, the data type of input_expr must be one of the data types for a fixed-point number. Data types for floating point numbers (for example, FLOAT) aren’t supported with this argument. |
Returns
The return type is based on the input type: - If the input expression is a FLOAT, the returned type is a FLOAT. - If the input expression is DECFLOAT, the returned type is DECFLOAT. - If the input expression is a NUMBER, the returned type is a NUMBER. If the input scale is constant: If the input scale is positive, the returned type has a scale equal to the input scale and has a precision large enough to encompass any possible result. - If the input scale is negative, the returned type has a scale of 0. - If the input scale isn’t constant, the returned type’s scale is the same as the input expression’s. If the scale is zero, then the value is effectively an INTEGER. For example: - The data type returned by ROUND(3.14::FLOAT, 1) is FLOAT. - The NUMBER returned by ROUND(3.14, 1) has scale 1 and precision at least 3. - The NUMBER returned by ROUND(-9.99, 0) has scale 0 and precision at least 2. - The NUMBER returned by ROUND(33.33, -1) has scale 0 and precision at least 3. If either the input_expr or the scale_expr is NULL, the function returns NULL.
Usage notes
- When you mix arguments by position and by name, all of the positional arguments must come before all of the named arguments.
- When you specify an argument by name, you can’t use double quotes around the argument name.
- If scale_expr is negative, it specifies the number of places before the decimal point to which to adjust the number. For example, if the scale is -2, the result is a multiple of 100.
- If scale_expr is larger than the input expression scale, the function doesn’t have any effect.
- By default, half-points are rounded away from zero for decimals. For example, -0.5 is rounded to -1.0. To change the rounding mode to round the value half to even (for example, to round -0.5 to 0), specify 'HALF_TO_EVEN' for the rounding_mode argument. Note If you specify the rounding_mode argument, the data type of the input_expr argument must be one of the data types for a fixed-point number.
- Floating point numbers are approximate values. A floating point number might not round as expected.
- If rounding brings the number outside of the range of values of the data type, the function returns an error.