Obtain the DECIMAL data type of the arithmetic result

The precision and scale of the arithmetic result depend on the precision and scale of the operands and on whether one of the operands is a floating-point decimal, as follows:
  • When one of the operands is a floating-point decimal, the arithmetic result is a floating-point decimal.

    For example, for an arithmetic operation between a fixed-point decimal of DECIMAL(8,3) and a FLOAT value, converts the FLOAT value to a floating-point decimal of DECIMAL(17). The arithmetic result has a data type of DECIMAL(17).

  • When both of the operands are fixed-point decimals, the arithmetic result is also a fixed-point decimal.

    The following table summarizes the rules for arithmetic operations on operands with definite scale (fixed-point decimals). In the following table, p1 and s1 are the precision and scale of the first operand, and p2 and s2 are the precision and scale of the second operand.

    Table 1. Precision and scale of fixed-decimal arithmetic results
    Operation Precision and scale of result
    Addition and Subtraction Precision: Scale: MIN(32, MAX(p1 - s1, p2 - s2) + MAX(s1, s2) + 1) MAX(s1, s2)
    Multiplication Precision: Scale: MIN(32, p1 + p2)

    s1 + s2;

    If (s1 + s2) > precision, the result is a floating-point decimal number (no scale value).

    Division Precision: Scale: 32

    Result is a floating-point decimal number.

    The sum: 32 - p1 + s1 - s2 cannot be negative.

If the data type of the result of an arithmetic operation requires the loss of significant digits, reports an error.