This page looks best with JavaScript enabled

Format Number as Currency in Javascript

 ·   ·  โ˜• 1 min read

Use Intl or the number prototype to format number to any specified currency.

1
2
3
4
5
6
const money = 420000;
const moneyFormatted = new Intl.NumberFormat("en-US", {
  style: "currency",
  currency: "USD",
}).format(money);
console.log(moneyFormatted); // $420,000.00
  • Javascript falls back on runtime locale if you specify an unavailable locale. This is used to format number
  • You can see the complete list of currency codes here.

Or, use number prototype-

1
2
3
4
5
6
7
const money = 420000;
const moneyFormatted = money.toLocaleString("en-IN", {
  maximumFractionDigits: 2,
  style: "currency",
  currency: "INR",
});
console.log(moneyFormatted); // โ‚นย 4,20,000.00

If you are using a framework that does not provide direct currency support just include the above in a globally accessible script and use it everywhere. For example, you would define the format in global filters in Vue and use that filter wherever needed.

Stay in touch!
Share on

Prashanth Krishnamurthy
WRITTEN BY
Prashanth Krishnamurthy
Technologist | Creator of Things