How to Format Currency in ES6 with Intl.NumberFormat

Samantha Ming
2 min readAug 27, 2018
Code Tidbit: How to Format Currency in ES6

You can now use the NumberFormat instance to format any number into a currency value.

const money = 💰;
// Old Way
money.toLocaleString('en-US',
{style: 'currency', currency: 'USD'}
);
// ✅ ES6 Way
new Intl.NumberFormat('en-US',
{ style: 'currency', currency: 'USD' }
).format(money);

More Currency Conversion

const money = 10000; 
// '€ 10,000.00'
new Intl.NumberFormat('de-DE',
{ style: 'currency', currency: 'EUR' }
).format(money);
// 'JP¥ 10,000'
new Intl.NumberFormat('jp-JP',
{ style: 'currency', currency: 'JPY' }
).format(money);
// 'CN¥ 10,000.00
'new Intl.NumberFormat('zh-CN',
{ style: 'currency', currency: 'CNY' }
).format(money);

Understanding the Parameter

Let’s talk about the parameters. It’s made up of the locales and the options object.

new Intl.NumberFormat([locales[, options]])

A. Parameter: Locales

First, you have the locales, this is the language and region settings. It is made up of language code and the country code.

language code + country

--

--

Samantha Ming

Frontend Developer sharing weekly JS, HTML, CSS code tidbits🔥 Discover them all on samanthaming.com 💛