javascript

How to Format Numbers As A Currency String in Javascript


In this article, you will learn how to format numbers as a currency string in Javascript.

Let’s say you have a number variable ‘a’ with value 12345.60

var a = 12345.60;

In order to format numbers as a currency, you can use the Intl.NumberFormat()method. In this example, you will be formatting a number into a currency of type USD.

var a = 12345.60;

var options = { style: 'currency', currency: 'USD' };

console.log(new Intl.NumberFormat('en-US', options).format(a));
// => "$12,345.60"

Note: The Intl.NumberFormat() method functions by formatting a number according to the locale and formatting options.


Share on social media

//