The JavaScript Intl.NumberFormat object
The Intl.NumberFormat object formats numbers for a locale — currency, percentages, and proper thousands separators. new Intl.NumberFormat("en-US", { style: "currency", currency: "USD" }).format(1234.5) gives "$1,234.50". It's the correct way to display money, far better than manual string work or toFixed().
Overview
Intl.NumberFormat formats numbers the way humans in a given locale expect — with the right thousands separators, decimal marks, currency symbols and percentage signs. You create a formatter with a locale and options, then call .format(number) on it. It's part of the built-in Intl internationalization API, and it's the right tool for displaying money, percentages and large numbers.
The headline use is currency: new Intl.NumberFormat("en-US", { style: "currency", currency: "USD" }).format(1234.5) produces "$1,234.50" — correct symbol, grouping and decimals, all handled for you. Change the locale and currency and it adapts: "de-DE" with "EUR" gives "1.234,50 €". Other styles include "percent" (which also multiplies by 100), "decimal" and "unit".
Why not just use toFixed() and add a "$"? Because that breaks for other locales, large numbers and negative values, and ignores grouping. Intl.NumberFormat gets all of that right. One performance note: creating a formatter has a cost, so if you're formatting many numbers, create the formatter once and reuse it rather than constructing one per value. The convenience method number.toLocaleString() uses the same engine for one-off formatting.
Syntax
const fmt = new Intl.NumberFormat("en-US", {
style: "currency",
currency: "USD"
});
fmt.format(1234.5); // "$1,234.50"
new Intl.NumberFormat("en-US", { style: "percent" }).format(0.25); // "25%"
(1234.5).toLocaleString("en-US"); // "1,234.5" (one-off)
Example
<pre id="out" style="font:14px ui-monospace,monospace"></pre>
<script>
const usd = new Intl.NumberFormat('en-US', { style: 'currency', currency: 'USD' });
const eur = new Intl.NumberFormat('de-DE', { style: 'currency', currency: 'EUR' });
document.getElementById('out').textContent =
'USD: ' + usd.format(1234.5) + '\n' +
'EUR: ' + eur.format(1234.5) + '\n' +
'pct: ' + new Intl.NumberFormat('en-US', { style: 'percent' }).format(0.25);
</script>
Best practices
- Use
Intl.NumberFormatfor currency and percentages, not manual strings or toFixed(). - Create the formatter once and reuse it when formatting many numbers — construction is costly.
- Pass an explicit locale and currency for predictable output.
- Use
number.toLocaleString()for a quick one-off format with the same engine.
Frequently asked questions
How do I format currency in JavaScript?
new Intl.NumberFormat("en-US", { style: "currency", currency: "USD" }).format(amount), which adds the symbol, separators and decimals correctly.Why not just use toFixed() for money?
Intl.NumberFormat does all of that.How do I format a percentage?
{ style: "percent" } — note it multiplies by 100, so pass 0.25 to get "25%".How do I make number formatting fast?
Intl.NumberFormat instance and reuse it for every value, instead of constructing a new one each time.