DEV Community

Cover image for Local currencies in Javascript
chandra penugonda
chandra penugonda

Posted on

1 1

Local currencies in Javascript

Convert number to local currencies using javascript

The toLocaleString() returns a number as a string, using local language format.

The language format depends on the locale setup on your computer.

Syntax

number.toLocaleString(locales, options)
Enter fullscreen mode Exit fullscreen mode
const a = 232332323
Enter fullscreen mode Exit fullscreen mode

Format a number into a currency string, using the locale specific of USA:

a.toLocaleString('en-US',{style:'currency', currency:'USD'})

output: '$232,332,323.00'
Enter fullscreen mode Exit fullscreen mode

Format a number into a currency string, using the locale specific of INR:

b.toLocaleString('en-IN',{style:'currency', currency:'INR'})

output: '$232,332,323.00'
Enter fullscreen mode Exit fullscreen mode

Reference

Top comments (0)

The best way to debug slow web pages cover image

The best way to debug slow web pages

Tools like Page Speed Insights and Google Lighthouse are great for providing advice for front end performance issues. But what these tools can’t do, is evaluate performance across your entire stack of distributed services and applications.

Watch video