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/

Sentry mobile image

App store rankings love fast apps - mobile vitals can help you get there

Slow startup times, UI hangs, and frozen frames frustrate users—but they’re also fixable. Mobile Vitals help you measure and understand these performance issues so you can optimize your app’s speed and responsiveness. Learn how to use them to reduce friction and improve user experience.

Read full post →

Top comments (0)