You can use the va_arg macro to accept a packed decimal data of the form (n,p).You can write packed decimal constants to a file, and scan them back.
The following figure shows you how to use the va_arg macro to accept a packed decimal data of the form decimal(n,p). The va_arg macro returns the current packed decimal argument.
Figure 285. ILE C Source to Use the va_arg Macro with a Packed Decimal Data Type
|
The output is as follows:
+--------------------------------------------------------------------------------+ | Number of char. printed when vargf is called first time is: 13 | | Number of char. printed when vargf is called second time is : 27 | | Press ENTER to end terminal session. | +--------------------------------------------------------------------------------+
The following example shows you how to write packed decimal constants to a file, and how to scan them back. In addition, the example shows you how to pass a packed decimal array to a function.
Figure 286. ILE C Source to Write Packed Decimal Constants to a File and Scan Them Back
|
The output is as follows:
+--------------------------------------------------------------------------------+ | b[0]=12.35 | | b[1]=25.00 | | b[2]=-19.58 | | Press ENTER to end terminal session. | +--------------------------------------------------------------------------------+
The following example shows how to use the %D(*,*) specifier with the printf() function. If n and p of the variable to be printed do not match with the n and p in the conversion specifier %D(n,p), the behavior is undefined. Use the unary operators digitsof (expression) and precisionof (expression) in the argument list to replace the * in D(*,*) whenever the size of the resulting type of a packed decimal expression is not known.
Figure 287. ILE C Source to Print Packed Decimal Constants
|
The output is as follows:
+--------------------------------------------------------------------------------+ | op_1 = 1234.12 | | op_2 = -12345678.12 | | Press ENTER to end terminal session. | +--------------------------------------------------------------------------------+
(C) Copyright IBM Corporation 1992, 2005. All Rights Reserved.