Key points
- Intl.NumberFormat and Intl.DateTimeFormat format prices and dates per locale with zero dependencies.
- Create formatters once and reuse them, especially when rendering lists or tables.
- Watch your tests: French output uses non-breaking spaces, not regular ones.
In bilingual sites and SaaS dashboards we still regularly find prices formatted by hand: a toFixed(2), a string replace for the decimal separator, a currency symbol glued on. It holds until an amount passes 999, the site switches language, or a customer wants to be billed in Swiss francs. Browsers have been able to do all of this properly for years through the Intl API.
Prices with Intl.NumberFormat
Create one formatter per locale and currency, then call it as often as you like. The locale can come straight from the page’s lang attribute, which WordPress or your framework already sets.
const lang = document.documentElement.lang || 'fr-FR';
const priceFormat = new Intl.NumberFormat(lang, {
style: 'currency',
currency: 'EUR',
});
// Amounts come from the API in cents to avoid float errors
function formatPrice(cents) {
return priceFormat.format(cents / 100);
}
formatPrice(129050); // fr-FR: "1 290,50 €" en-GB: "€1,290.50"
The formatter knows each locale’s rules: where the symbol goes, the decimal separator, digit grouping, and how many decimals a currency uses. Switching currency is a parameter change, not a rewrite. On our projects amounts are always stored in cents on the server; converting to a decimal only happens at display time.
Dates and relative times
Dates work the same way. Set the time zone explicitly: without it the visitor’s device zone is used, which is sometimes what you want and sometimes the reason a deadline shows up a day early.
const dateFormat = new Intl.DateTimeFormat(lang, {
dateStyle: 'long',
timeStyle: 'short',
timeZone: 'Europe/Paris',
});
dateFormat.format(new Date('2026-10-29T13:45:00Z'));
// fr-FR: "29 octobre 2026 à 14:45"
const relative = new Intl.RelativeTimeFormat(lang, { numeric: 'auto' });
relative.format(-1, 'day'); // "hier" / "yesterday"
relative.format(3, 'hour'); // "dans 3 heures" / "in 3 hours"
Intl.RelativeTimeFormat replaces the home-made “X minutes ago” helpers that end up in every codebase. With numeric: 'auto' you get “yesterday” instead of “1 day ago”.
Traps we have hit in production
Tests first. French uses a narrow non-breaking space to group digits and a non-breaking space before the euro sign. A test comparing against a string typed on a keyboard fails even though the output looks identical on screen.
// Fails: French uses non-breaking spaces, not regular ones
expect(formatPrice(129050)).toBe('1 290,50 €');
// Robust: normalise the spaces before comparing
const normalise = (s) => s.replace(/[u00A0u202F]/g, ' ');
expect(normalise(formatPrice(129050))).toBe('1 290,50 €');
Then performance. Building a formatter is much more expensive than calling it. We once fixed a dashboard that created an Intl.NumberFormat for every table cell; hoisting it to module level was enough to make sorting feel instant again.
Finally, server rendering. If the same value is formatted in Node or PHP and then again in the browser, locale data can differ slightly between runtimes and cause hydration mismatches. Format in one place, or pass identical options on both sides.
FAQ
Do I still need a library like Moment.js?
Not for display. Date arithmetic such as adding months or counting business days is still nicer with a small library, but formatting belongs to Intl.
How do I show a price without the currency symbol?
Use style: ‘decimal’ with minimumFractionDigits: 2, or formatToParts() to get each piece separately, for example to render the cents in a smaller font.
Building a multilingual site or an app with prices in several currencies? Our team builds front-ends that are tested, reliable and ready for international users.



