|
|
|
|
|
by felixfbecker
815 days ago
|
|
and different currencies have different default precisions. So if you're dealing with multiple currencies, now you need both client and server to have a map of all currency precisions for formatting purposes that they agree on. What's worse is that these things can also change over time and there is sometimes disagreement over what the canonical value is. E.g. ISO 4217 (used by Safari, Firefox and NodeJS) will say that the Indonesian Rupiah (IDR) uses 2 decimal digits, while Unicode CLDR (used by Chrome) will say that they use 0 decimal digits. The former is the more "legalistic" definition, while the latter matches how people use the currency in reality. This is not a real issue if you transfer amounts as decimal strings and then pass those to the Intl API for formatting (the formatting will just be different but still correct), but it's catastrophic if you use scaled-up integers (all amounts will be off by magnitudes). For this reason I would always store currency amounts in an appropriate DECIMAL type in the DB and send currency amounts as strings over the wire. |
|