Internal fixed-point decimal format

The DECIMAL and MONEY data types store fixed-point values in a proprietary internal format for HCL Informix®: the dec_t structure. This structure holds the internal (binary) format of a DECIMAL or MONEY value.

The following code fragment shows how the dec_t structure holds the internal (binary) format of a DECIMAL or MONEY value.
#define DECSIZE 16

struct decimal
   {
   short dec_exp;
   short dec_pos;
   short dec_ndgts;
   char  dec_dgts[DECSIZE];
   };

typedef struct decimal dec_t;
This dec_t structure stores the number in pairs of digits. Each pair is a number in the range 00 - 99. (Therefore, you can think of a pair as a base-100 digit.) The following table shows the four parts of the dec_t structure.
Table 1. Fields in the dec_t structure
Field Description
dec_exp The exponent of the normalized dec_t type number

The normalized form of this number has the decimal point at the left of the leftmost digit. This exponent represents the number of digit pairs to count from the left to position the decimal point (or as a power of 100 for the number of base-100 numbers).

dec_pos The sign of the dec_t type number
The dec_pos can assume any one of the following three values:
1
When the number is zero or greater
0
When the number is less than zero
-1
When the value is null
dec_ndgts The number of digit pairs (number of base-100 significant digits) in the dec_t type number

This value is also the number of entries in the dec_dgts array.

dec_dgts[] A character array that holds the significant digits of the normalized dec_t type number, assuming dec_dgts[0] != 0

Each byte in the array contains the next significant base-100 digit in the dec_t type number, proceeding from dec_dgts[0] to dec_dgts[dec_ndgts].

The following table shows some sample dec_t values.
Table 2. Sample decimal values and dec_t structure field values
Sample value dec_exp value dec_pos value dec_ndgts value dec_dgts[] valu
-12345.6789 3 0 5

dec_dgts[0] = 01
dec_dgts[1] = 23
dec_dgts[2] = 45
dec_dgts[3] = 67
dec_dgts[4]= 89

1234.567 2 1 4

dec_dgts[0] = 12
dec_dgts[1] = 34
dec_dgts[2] = 56
dec_dgts[3] = 70

-123.456 2 0 4

dec_dgts[0] = 01
dec_dgts[1] = 23
dec_dgts[2] = 45
dec_dgts[3] = 60

480 2 1 2

dec_dgts[0] = 04
dec_dgts[1] = 80

.152 0 1 2

dec_dgts[0] = 15
dec_dgts[1] = 20

-6 1 0 1 dec_dgts[0] = 06

The mi_decimal data type uses the dec_t structure to hold the binary representation of a DECIMAL value. The mi_money data type uses the dec_t structure to hold the binary representation of a MONEY value.