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 €
.
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.