This parameter allows you to specify the rounding mode
for decimal floating point (DECFLOAT). The rounding mode affects decimal
floating-point operations in the server, and in LOAD.
- Configuration type
- Database
- Parameter type
- Configurable
See Effects of changing decflt_rounding.
- Default [range]
- ROUND_HALF_EVEN [ROUND_CEILING, ROUND_FLOOR, ROUND_HALF_UP, ROUND_DOWN]
DB2® database
systems support five IEEE-compliant decimal floating point rounding
modes. The rounding mode specifies how to round the result of a calculation
when the result exceeds the precision. The definitions for all the
rounding modes are as follows:
- ROUND_CEILING
- Round towards +infinity. If all of the discarded digits are zero
or if the sign is negative the result is unchanged. Otherwise, the
result coefficient should be incremented by 1 (rounded up).
- ROUND_FLOOR
- Round towards -infinity. If all of the discarded digits are zero
or if the sign is positive the result is unchanged. Otherwise, the
sign is negative and the result coefficient should be incremented
by 1.
- ROUND_HALF_UP
- Round to nearest; if equidistant, round up 1. If the discarded
digits represent greater than or equal to half (0.5) of the value
of a 1 in the next left position then the result coefficient should
be incremented by 1 (rounded up). Otherwise, the discarded digits
(0.5 or less) are ignored.
- ROUND_HALF_EVEN
- Round to nearest; if equidistant, round so that the final digit
is even. If the discarded digits represent greater than half (0.5)
the value of a one in the next left position, then the result coefficient
should be increment by 1 (rounded up). If they represent less than
half, then the result coefficient is not adjusted, that is, the discarded
digits are ignored. Otherwise, if they represent exactly half, the
result coefficient is unaltered if its rightmost digit is even, or
incremented by 1 (rounded up) if its rightmost digit is odd, to make
an even digit. This rounding mode is the default rounding mode as
per IEEE decimal floating point specification and is the default rounding
mode in DB2 database products.
- ROUND_DOWN
- Round towards 0 (truncation). The discarded digits are ignored.
Table 1 shows the result
of rounding of 12.341, 12.345, 12.349, 12.355, and -12.345, each to
4 digits, under different rounding modes:
Table 1. Decimal
floating point rounding modesRounding mode |
12.341 |
12.345 |
12.349 |
12.355 |
-12.345 |
ROUND_DOWN |
12.34 |
12.34 |
12.34 |
12.35 |
-12.34 |
ROUND_HALF_UP |
12.34 |
12.35 |
12.35 |
12.36 |
-12.35 |
ROUND_HALF_EVEN |
12.34 |
12.34 |
12.35 |
12.36 |
-12.34 |
ROUND_FLOOR |
12.34 |
12.34 |
12.34 |
12.35 |
-12.35 |
ROUND_CEILING |
12.35 |
12.35 |
12.35 |
12.36 |
-12.34 |
Effects of changing decflt_rounding
- Previously constructed materialized query tables (MQTs) could
contain results that differ from what would be produced with the new
rounding mode. To correct this problem, refresh potentially impacted
MQTs.
- The results of a trigger may be affected by the new rounding mode.
Changing it has no effect on data that has already been written.
- Constraints that allowed data to be inserted into a table, if
reevaluated, might reject that same data. Similarly constraints that
did not allow data to be inserted into a table, if reevaluated, might
accept that same data. Use the SET INTEGRITY statement to check for
and correct such problems. The value of a generated column whose calculation
is dependent on decflt_rounding could be different
for two identical rows except for the generated column value, if one
row was inserted before the change to decflt_rounding and
the other was inserted after.
- The rounding mode is not compiled into sections. Therefore, static
SQL does not need to be recompiled after changing decflt_rounding.
Note: The value of this configuration parameter is not changed
dynamically but will become effective only after all applications
disconnect from the database. If the database is activated, it must
be deactivated.