NotoriousWebmaster
NotoriousWebmaster

Reputation: 3568

react-intl currency displayed without decimals

I have a requirement to display currency without decimals. We want the currency decorator ($), and the commas and spaces, as dictated by the locale, but no decimals.

I've tried the maximumFractionDigits set to 0. That works, but removes the commas and currency decorator.

Also, I have not been able to replicate the example in the docs at https://github.com/yahoo/react-intl/wiki/API#number-formatting-apis:

formatNumber(1000, {style: 'currency', currency: 'USD'}); // $1,000

I get $1,000.00.

Thanks for your help.

Upvotes: 4

Views: 5759

Answers (1)

NotoriousWebmaster
NotoriousWebmaster

Reputation: 3568

Turns out you need to specify both minimum and maximum fraction digits, like so:

formatNumber(1000, {style: 'currency', currency: 'USD',
  minimumFractionDigits: 0, maximumFractionDigits: 0}); // $1,000

Hope this helps.

Upvotes: 8

Related Questions