0

I am working on an application using React Native where I need to show currency in Euro and in rupees as well.

I am using Javascript's Intl for formatting the currency as per the locale using en-IN for rupees and en-GB for euro.

but the currency is shown with different formatting on iOS and in android, in iOS the currency is showing correctly for IN like 3,74,73,474 but the same is shown on android with this format: 37,473,474. Not sure how do I approach for this. Below is the utility function I wrote for formatting:

getformattedCurrency(value) {
   const formatter = new Intl.NumberFormat('en-IN', {
      style: 'currency',
      currency: 'INR'
      minimumFractionDigits: 0,
      maximumFractionDigits: 0,
   });
   return formatter.format(value);
}

I know that android's native have DecimalFormat to do this but I want to achieve this via JS only.

Any help is appreciated ! Thanks.

6
  • Can you provide an example number that you trying to convert and results that you get, those ### not giving enough information on result. Also you may try it without minimum and maximum fraction digits parameters. If you want have rounded number you can do that math before converting. Jan 8, 2019 at 7:44
  • @maximelian1986 I have edited the question to provide real data. Please have a look at it. Jan 8, 2019 at 7:56
  • Did you debuged it? Do you getting different values from that method or you see different values on your app ui? May be something after that method render result number in that strange form? And does your initial number is 37473.474 ? Jan 8, 2019 at 8:05
  • Yes i have debugged and then only came to the conclusion that the method is returning different values and the initial number is 37473474 not 37473.474 Jan 8, 2019 at 8:22
  • I still testing but now I noticed that you have typo, you missing comma before minimumFractionDigits param...may be that is in your code as well if you copy/paste it here. Jan 9, 2019 at 13:02

1 Answer 1

1

Looks like for some reason it is unable to select which script from Intl library to use. So

import 'intl';
import 'intl/locale-data/jsonp/en-IN';
import 'intl/locale-data/jsonp/en';

When you import en-IN separatly it works on android. Unable test on iPhone.

5
  • Or may be it is expected behavior and you need to import each currency separately. Jan 11, 2019 at 12:44
  • Okay thanks. I will check this and will confirm ! Thanks :) Jan 15, 2019 at 10:34
  • this works in both platforms. Sorry to revert late. Thanks again ! Mar 17, 2019 at 7:07
  • where should I import this?
    – Nabeel K
    Apr 6, 2021 at 7:19
  • I am getting error saying intl could not be found within the project
    – Nabeel K
    Apr 6, 2021 at 7:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.