Php Numberformatter: Currency Display Is Not Financial Arithmetic
The same amount, different presentation An online shop expands from one country to several markets. Its developers initially display prices with number_format($amount, 2) and concatenate a currency symbol. The result looks plausible in their home market but quickly becomes confusing elsewhere. Some locales put the symbol after the number. Some use a comma as the decimal separator. Some use different grouping characters, including nonbreaking spaces that look identical to ordinary spaces. A monetary amount is not merely a floating-point number followed by a symbol. It has a currency code, a value, a locale-dependent presentation, and sometimes business-specific rounding rules. These concerns should not be collapsed into a single formatting function.
What NumberFormatter actually does PHP’s intl extension exposes ICU’s NumberFormatter class. With the CURRENCY style, the formatter applies locale conventions to a supplied amount and ISO currency code. The locale determines how the result is written; the currency code identifies what is being displayed. The formatter does not exchange dollars for euros and does not know the customer’s current exchange rate. That distinction is central to a correct implementation. Displaying 125 Canadian dollars for a French-speaking customer should change the punctuation and currency labeling, not silently convert the monetary value. The application should select its presentation locale explicitly rather than relying on whatever default locale happens to be installed on a server.
