Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 372
NotoriousWebmaster Avatar asked Mar 06 '23 00:03

NotoriousWebmaster


1 Answers

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.

like image 103
NotoriousWebmaster Avatar answered Mar 14 '23 19:03

NotoriousWebmaster