Rizal prints a tea invoice for a buyer abroad: type a locale tag, and four real Intl formatters write the amount, the date, the due day and the goods, a…
Why it matters
An app used across countries (or just in Indonesia with rupiah written right) needs this. Intl needs no library, is accurate per language and is already in the browser. Writing your own formatter is almost always wrong at the edges.
The key idea
Never write numbers and dates yourself: Intl knows every locale’s rules
Common mistakes
Rupiah shows without group separators when the country changes Building 'Rp ' + n has no group separator and is wrong for other locales. Use NumberFormat with style: 'currency'.
A long list gets slow because the formatter is built inside a loop Building an Intl formatter is expensive. Build it once outside the loop and reuse its .format().
Formatting currency throws although the number is valid{ style: 'currency' } without currency throws a TypeError. The currency code (IDR, USD) is required.
Try it in this playground
Switch the locale to de-DE Dots and commas trade places, the € moves to the back, the month becomes Oktober.
Move the due date -1 → yesterday, 1 → tomorrow, 3 → in 3 days: numeric: 'auto' uses a word when there is one.
Type a locale the browser does not know xx-YY is a valid tag but has no data: the browser uses another language without an error.
Pick currency: none style: 'currency' without a currency throws a TypeError. The code is required.