DEV Community

Jyotishman Saikia
Jyotishman Saikia

Posted on

2 1

Format a number to any currency using Javascript

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/

AWS Security LIVE!

Join us for AWS Security LIVE!

Discover the future of cloud security. Tune in live for trends, tips, and solutions from AWS and AWS Partners.

Learn More

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

Retry later