Format a number to any currency using Javascript

Jyotishman Saikia - Jul 10 '21 - - Dev Community

This article will explain you how to convert a number to any currency like - INR, USD, EUR etc using the Javascript international number format API- Intl.NumberFormat.

Basic Usage-

var number = 3500;

If you don't specify any locales, it will return the formatted number based on your location.

image

I am from India , so it returned the Indian formatted number.

Format number using locales-

You can specify location to format number according to it.

image

Format number to any currency using locale-

To convert number to currency you need to mention the style and the currency format-

  1. style= currency
  2. currency= USD, INR, EUR etc
For Indian currency-

image

For US dollar currency-

image

Using this Intl.NumberFormat you can also format other number like- km/hr, litres, etc,

If you liked this content you can support me by following me on twitter and Instagram for more such contents-

Twitter - https://twitter.com/frontend_jsx
Instagram - https://www.instagram.com/frontend.jsx/

. . . . . . . . . . . . . . . . . . . . .