A lot of the answers to the questions about the accuracy of float
and double
recommend the use of decimal
for monetary amounts. This works because today all currencies are decimal except MGA and MRO, and those have subunits of 1/5 so are still decimal-friendly.
But what about the software used in U.S. stock markets when prices were in 1/16ths of dollar? The accuracy of binary data types wouldn't have been an issue, right?
Going further back, how did pre-1971 British accounting software deal with pounds, shillings, and pence? Did their versions of COBOL have a special PIC
clause for it? Were all amounts stored in pence? How was decimalisation handled?
Today, only two countries have non-decimal currencies: Mauritania, where 1 ouguiya = 5 khoums, and Madagascar, where 1 ariary = 5 iraimbilanja.
Most currencies have two decimals. Some currencies do not have decimals, and some have three decimals. For example: 10 GBP: GBP has two decimals, so in minor units submit an amount of 1000.
Not all currencies across the world have two decimal places. Some have zero decimal places (e.g. Japanese yen), some have three decimal places (the dinar in many countries), and in Madagascar the minor unit is one fifth of the major unit so currency would be written to one decimal place.
/ˌdes.ɪ.məl ˈkɝː. ən.si/ a money system in which a smaller unit can be multiplied by ten or a 100 to make up a bigger unit: The UK and the US both have decimal currencies. Currencies.
PL/I had a type specifically for British currency - I don't know about COBOL. The British currency at one time incorporated farthings, or a quarter of a penny; I'm not sure though that computers had to deal with those, just with half pennies or ha'pennies.
Accurate accounting usually uses special types - representing decimals exactly. The new IEEE 754 has support for floating-point decimals, and some chips (notably IBM pSeries) have such support in hardware.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With