CCK

9 August, 2007

For one of the projects I’m currently working on, we needed to be able to store monetary values. This seems utterly simple at first, but there are many details that need attention.

The obvious one: multiple currencies. Luckily, this was easily solved by using the excellent Currency module, which includes a Currency API module, written by Khalid Baheyeldin of 2BITS. The tricky part is the ability to read from and write to different number notations (and thus store the amount notation-independently). The number one thousand for example is written like 1,000 in the U.S., but it’s written like 1.000 in Belgium. In the U.S. they use a dot as the decimal separator, in Europe a comma.
The default decimal separator is the comma and the default digit group separator is the space, this is conform with ISO 31-0. A function to parse numbers (the most difficult part) is absent in PHP, one to format numbers however, is present.