The following example illustrates different conversions from packed decimal types to packed decimal types that have different sizes. If the value of the packed decimal type to be converted is not within the range of values that can be represented exactly, the value of the packed decdimal type is truncated. If truncation occurs in the fractional part, the result is truncated, and there is no run-time error.
Figure 272. ILE C Source to Convert Packed Decimals
|
If assignment causes truncation in the integral part, then there is a run-time error. A run-time exception occurs when an integral value is lost during conversion to a different type, regardless of what operation requires the conversion. See Understanding Packed Decimal Data Type Errors for an example of run-time exceptions.
Examples:
There is no warning or error during compilation on assignment to a smaller target. See Understanding Packed Decimal Data Type Errors for information on compile-time and run-time errors during conversion.
The following example shows conversion from one packed decimal type to another with a smaller precision. Truncation on the fractional part results.
Figure 273. ILE C Source to Convert a Packed Decimal to a Packed Decimal with Smaller Precision
|
The next example shows conversion from one packed decimal type to another with a smaller integral part. Truncation on the integral part results. The #pragma nosigtrunc directive turns off exceptions generated because of overflow.
Figure 274. ILE C Source to Convert a Packed Decimal to a Packed Decimal with Smaller Integral Part
|
The next example shows conversion from one packed decimal type to another with a smaller integral part and smaller precision. Truncation on both integral and fractional parts results. The #pragma nosigtrunc directive turns off exceptions generated because of overflow.
|
(C) Copyright IBM Corporation 1992, 2005. All Rights Reserved.