J
Jim Janney
Martin Gregorie said:Actually, I've yet to see a financial package that used anything but
integers for currency amounts, so in USD or GBP the amounts would be
cents and pence respectively the decimal point is just interpolated when
the value is displayed, e.g. in COBOL:
01 AMOUNT COMP SYNC PIC S9(9).
01 DISP_AMOUNT PIC -Z,ZZZ,ZZ9.99 BLANK WHEN ZERO.
MOVE 150 TO AMOUNT.
.....
MOVE AMOUNT TO DISP-AMOUNT.
would output the amount, $1.50 held internally as 150 cents, as
" 1.50"
Interest and exchange rates, etc. is quite another matter: whether they
are held internally as fixed point decimal or floating point is entirely
up to the system designer and the compiler writer.
In practice there's a strong tendency toward whatever the programming
language makes convenient. The system I work with was originally
written in RPG. RPG strongly favors fixed point decimal, and that's
what is mostly used in the RPG code and in the data base, for example
9 digits with 2 decimal places for dollar and cent amounts and 5
digits with 5 decimal places for interest rates. In Java we have USD
and Percent classes that use BigDecimal internally.
Using integers for currency amounts is numerically sound but relies on
the programmer to keep track of the decimal position. Not bad for
small projects but it would make me nervous for larger projects where
there's significant turnover among the programmers.