Share this page

Internal Structure of a Decimal Value

A DECIMAL of precision 'P' is an array of unsigned chars of size (1+INT(Precision/2)) where the last nibble is the sign and preceding nibbles are the digits of the number (0x0-0x9) including leading zeros.

The size of the array is defined for the declared size of the variable, not the size actually used (leading and trailing zeros are stored). If there is an even number of digits, the first nibble in the array is unused.

The position of the decimal point cannot be determined from the DECIMAL data itself; it is specified in the metadata ('scale').

The Sign nibble uses values 0xa, 0xc, 0xe, and 0xf for positive numbers (0xc being preferred) and 0xb and 0xd for negative numbers (0xd being preferred).

Here is a sample array: