Share this page

Arithmetic Operations on Decimal Data Types

In expressions that combine decimal values and return decimal results, the precision (total number of digits) and scale (number of digits to the right of the decimal point) of the result can be determined, as shown in the following table:

Precision | Scale | |

Addition and subtraction | Larger number of fractional digits plus largest number of non‑fractional digits + 1 (to a maximum of 39) | Scale of operand having the largest scale |

Multiplication | Total of precisions to a maximum of 39 | Total of scales to a maximum of 39 |

Division | 39 | (39 precision of first operand) + (scale of first operand) (scale of second operand) |

For example, in the following decimal addition operation:

1.234 + 567.89

the scale and precision of the result is calculated as follows:

Precision = 7

Calculated as 3 (larger number of fractional digits) + 3 (larger number of non‑fractional digits) + 1 = 7

Scale = 3

The first operand has the larger number of digits to the right of the decimal point

Result:

0569.124

Note: If the result of arithmetic using decimal data exceeds the declared precision or scale of the column to which it is assigned, OpenSQL truncates the result and does not issue an error.