Using Packed Decimal Data in a C Program

C language only
The packed decimal data type representation includes integral and fractional parts. The ILE C compiler supports the packed decimal data type as an extension to ISO C.
Note: This is strictly a C data type. C++ decimal support is provided in the bcd class. The header file is bcd.h. For more information, refer to the ILE C/C++ Language Reference.
You can use the packed decimal data type to:
  • Represent large numeric quantities accurately, especially in business and commercial applications for financial calculations. For example, the fractional part of a dollar can be represented accurately by two digits that follow the decimal point.
    Note: You do not have to use floating point arithmetic. Floating point is more suitable for scientific and engineering computations, which often use numbers that:
    • Are much larger than the largest packed decimal variable can store
    • Are much smaller than the smallest packed decimal, but do not have enough precision for commercial use
  • Declare type definitions, arrays, structures, and unions that have packed decimal members. You can apply operators (unary operators) on packed decimal variables. Bitwise operators do not apply to packed decimal data. The packed decimal data type in ILE C is compatible with packed decimal representations in RPG and COBOL. You can also define macros and call library functions with packed decimal arguments. The ILE C/C++ Language Reference contains information on the packed decimal data type.
    Note: To use the decimal, digitsof, and precisionof macros in your code, you must specify the <decimal.h> header file in your ILE C source.