Ad

Currency Getting Differently Formatted On IOS And Android With Same Locale

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.

Ad

Answer

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.

Ad
source: stackoverflow.com
Ad