Danilo.Micucci
Danilo.Micucci

Reputation: 83

How to format prices in JS

I'm using currencyFormatter for my prices, and I would like to present my prices with the euro sign after the price and a full stop instead of a comma

Ej. 10.000€ (10 thousand euro).

(10000).toLocaleString(xxxx, {
  style: 'currency',
  currency: 'USD',
});

Does anyone know which unit I should use in the xxxx? Thanks for your help!

Upvotes: 2

Views: 1257

Answers (2)

Zachary Haber
Zachary Haber

Reputation: 11037

I'd suggest playing around with the locales a bit, or just leave it as undefined to use the user's locale. It appears that 'de-DE' (Germany) appears fairly close to your desired format.

As for the euro sign, you need to have currency: 'EUR' for that.

console.log((10000).toLocaleString('de-DE', {
  style: 'currency',
  currency: 'EUR',
  maximumFractionDigits: 0
}));

number#toLocaleString uses the arguments from Intl.NumberFormat which I'd suggest reading through.

In this case, I used maximumFractionDigits to remove the values after the decimal point.

Upvotes: 2

Sean
Sean

Reputation: 1456

toLocaleString should be "en-US"

Upvotes: 0

Related Questions