Is there a functionality in JavaScript to convert values into specific locale formats?

Murtaza Mandvi picture Murtaza Mandvi · Mar 15, 2011 · Viewed 65.4k times · Source

Is there a built in function of JavaScript to convert a string into a particular locale (Euro in my case)?

E.g. 50.00 should get converted to 50,00 €.

Answer

Willem de Wit picture Willem de Wit · Mar 10, 2014

I found a way to do this at this page.

You can you toLocaleString without using toFixed before it. toFixed returns a string, toLocaleString should get a number. But you can pass an options object with toLocaleString, the option minimumFractionDigits could help you with the functionality toFixed has.

50.toLocaleString('de-DE', {
    style: 'currency', 
    currency: 'EUR', 
    minimumFractionDigits: 2 
});

Checkout all the other options you can pass with this function.