On Mon, 12 Jan 1998 17:32:04 GMT, manel@semic.es (Manel Falc') wrote:
>Hi,
>Why the storage of decimal(14,4) is 8 bytes and decimal(14,3) or
>decimal(14,5) is 9 ??
>( 8 for even decimals and 9 for odd decimals, it seems)
>according to the storage calculation: 14/2+1 -> 8 bytes
>
>
>Ciao,
>
> Manel
>
>-----------------------------------------------------
>SEMIC, S.A.
>Lleida (Catalunya)
>Spain
>-----------------------------------------------------
>Informix version: Informix SE 5.07 / RDS 4.x
>Operating system: Unix SCO V 5.04
>
Your calculation is too simple, unfortunately.
DECIMAL values are stored in base-100 units, so for each pair (or
part-pair) of digits before or after the decimal point requires 1
byte,
plus 1 byte for exponent and sign information.
For DECIMAL(14,4), the are 2 base-100 digits after the dp, 5 before,
and 1
extra, for 8 bytes overall. For DECIMAL(14,5), there are 3 base-100
digits
after the dp, and 5 before, plus the sign/exponent byte for a total of
9.
The last digit after the dp is always a multiple of 10, of course.
I think the current generation of manuals has this formula correct.
For example, the 9.1 Informix Guide to SQL: Reference specifies:
If the scale is odd: N = (precision + 4) / 2
If the scale is even: N = (precision + 3) / 2
Hence:
For odd scales and precision = 14, we get (14 + 4) / 2 = 9
For even scales and precision = 14, we get (14 + 3) / 2 = 8
It also points out that you can't have a DECIMAL(32,31) type.
Yours,
Jonathan Leffler (johnl@informix.com) #include <witticism.h>
Ciao,
Manel
-----------------------------------------------------
SEMIC, S.A.
Lleida (Catalunya)
Spain
-----------------------------------------------------
Informix version: Informix SE 5.07 / RDS 4.x
Operating system: Unix SCO V 5.04