DEV Community

Cover image for Local currencies in Javascript
chandra penugonda
chandra penugonda

Posted on

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)