Determining the Number of Digits in an Object

C language onlyIn ILE C, when you use the __digitsof operator with a packed decimal data type the result is an integer constant. The __digitsof operator can be applied to a packed decimal data type or a packed decimal constant expression. The __digitsof operator returns the total number of digits n in a packed decimal data type.

To determine the number of digits n in a packed decimal data type, follow the example shown in Figure 1:
Figure 1. Example of Code that Determines the Number of Digits in a Packed Decimal Data Type.
#include <decimal.h>

int n,n1;
decimal (5, 2) x;

n = __digitsof(x);           /* the result is n=5  */
n1 = __digitsof(1234.567d);  /* the result is n1=7 */

C++ language onlyIn ILE C++, when you use the member function DigitsOf() with a _DecimalT class template the result is an integer constant. The member function DigitsOf() can be applied to a _DecimalT class template object. The member function DigitsOf() returns the total number of digits n in a _DecimalT class template object.

To determine the number of digits n in a _DecimalT class template object, follow the example shown in Figure 2:
Figure 2. Example of Code that Determines the Number of Digits in a _DecimalT Class Template Object
#include <bcd.h>

int n,n1;
_DecimalT <5, 2> x;

n = x.DigitsOf();                  // the result is n=5