---
title: "How do I format a number as currency in JavaScript?"
description: "Format prices in JavaScript with Intl.NumberFormat and style currency. Covers locales, currency codes, decimal places, compact amounts and why you should avoid toFixed."
url: https://www.danny.engineering/answer/javascript/how-do-i-format-a-number-as-currency-in-javascript
author: Danny
published: 2026-11-27T00:00:00.000Z
updated: 2026-11-27T18:57:00.000Z
tags: ["Javascript"]
---

# How do I format a number as currency in JavaScript?

## The short answer


Use `Intl.NumberFormat` with `style: 'currency'` and an ISO 4217 currency code. It adds the right symbol, thousands separators and decimal places for the locale you give it.


```javascript
const gbp = new Intl.NumberFormat('en-GB', {
  style: 'currency',
  currency: 'GBP',
});

gbp.format(1234.5); // "£1,234.50"

(1234.5).toLocaleString('de-DE', { style: 'currency', currency: 'EUR' });
// "1.234,50 €"
```


## Why it happens


A price looks simple, but the rules change with the reader. The symbol can go before or after the number, the decimal separator can be a point or a comma, thousands can be grouped with commas, points or spaces, and some currencies, such as the Japanese yen, have no minor unit at all. Writing `'£' + price.toFixed(2)` gets all of this right for one country and wrong for the rest.


`Intl.NumberFormat` is built into every modern browser and Node. It knows these rules for each locale and currency, so you only choose the locale (how it looks) and the currency (what the money is).


## How to fix it


### Create a formatter and reuse it


The locale controls the format and the currency code controls the symbol and decimals. They are separate on purpose: a British reader looking at a price in US dollars should see `US$` in a British layout.


```javascript
const formatPrice = new Intl.NumberFormat('en-GB', {
  style: 'currency',
  currency: 'USD',
}).format;

formatPrice(49.99); // "US$49.99"

new Intl.NumberFormat('ja-JP', { style: 'currency', currency: 'JPY' })
  .format(1500); // "￥1,500"
```


Creating a formatter has a cost, so make one per locale and currency and reuse it, for example at module level.


### Control decimal places


Currencies have a default number of decimals. You can change it, for example to show whole pounds on a pricing page.


```javascript
const wholePounds = new Intl.NumberFormat('en-GB', {
  style: 'currency',
  currency: 'GBP',
  maximumFractionDigits: 0,
});

wholePounds.format(1299.99); // "£1,300"
```


When you lower `maximumFractionDigits` below the currency default, also set `minimumFractionDigits` to the same or lower value if you hit a range error in older engines.


### Change how the currency is shown


`currencyDisplay` switches between the symbol, a narrow symbol, the ISO code and the full name.


```javascript
const amount = 20;

new Intl.NumberFormat('en-GB', { style: 'currency', currency: 'USD', currencyDisplay: 'narrowSymbol' }).format(amount);
// "$20.00"

new Intl.NumberFormat('en-GB', { style: 'currency', currency: 'USD', currencyDisplay: 'code' }).format(amount);
// "USD 20.00"

new Intl.NumberFormat('en-GB', { style: 'currency', currency: 'USD', currencyDisplay: 'name' }).format(amount);
// "20.00 US dollars"
```


### Show negative amounts as accounts do


Finance screens often show losses in brackets. Set `currencySign` to `"accounting"`.


```javascript
new Intl.NumberFormat('en-US', {
  style: 'currency',
  currency: 'USD',
  currencySign: 'accounting',
}).format(-42); // "($42.00)"
```


### Use compact notation for large figures


For dashboards, `notation: 'compact'` shortens big numbers.


```javascript
new Intl.NumberFormat('en-GB', {
  style: 'currency',
  currency: 'GBP',
  notation: 'compact',
}).format(2_500_000); // "£2.5M"
```


## Common pitfalls

- Storing money as floating-point pounds. `0.1 + 0.2` is not exactly `0.3`. Store amounts as integers in the minor unit (pence or cents) and divide only when formatting.
- Using `toFixed(2)` for display. It rounds, but it adds no symbol or separators and ignores locale.
- Hard-coding two decimals. Some currencies use zero or three, and `Intl` already knows which.
- Assuming the output uses ordinary spaces. Some locales insert a non-breaking or narrow non-breaking space, so string comparisons in tests can fail. Compare with `formatToParts` or normalise the spaces first.
- Formatting on the server and the client with different locales or ICU data, which can cause hydration mismatches. Pass the locale explicitly.

## Related reading

- [MDN: Intl.NumberFormat](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat)
- [MDN: Intl.NumberFormat() constructor options](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/NumberFormat)
