Response-native.toLocaleString () not working on android

I am using .toLocaleString() for response-native to output my number. Everyone works on iOS, but doesn't seem to work on Android. Is this normal or? Do I need to use the function for decimal?

enter image description here

+13
source share
5 answers

you can use

 number.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",") 
+5
source

The reason for this is the very old version of JavaScriptCore used by reacting. iOS embeds its own version, so it works fine there.

The problem still exists (some read about where it goes https://github.com/facebook/react-native/issues/19737 )

And more information about this from Airbnb developers https://medium.com/airbnb-engineering/react-native-at-airbnb-the-technology-dafd0b43838 (search for "JavaScriptCore inconsistencies")

+2
source

You can also use Intl.NumberFormat as follows:

 new Intl.NumberFormat('en-US', { style: 'currency', currency: 'USD' }).format(amount) 
0
source

Easy to fix, 30 seconds: use this polyfill .

0
source

This issue is related to the Javascript core used to trigger the native reaction in Android, and not to the native reaction itself. To overcome this, you will need to integrate the latest javascript core into your Android build or upgrade your own version to 0.59.

Details are documented in the Android Build UA repository .

Now for people who would like to format locale strings without having to integrate the entire javascript core, Javascript has an Internationalization API that allows you to format numbers in a language-sensitive format. Documentation is available on MDN.

This API is not available on Android and needs to be populated using Intl

Install the Intl library at the root of your project

 yarn add intl 

And then in the index file of your project (index.js) add the following code at the top of the file:

 if(Platform.OS === 'android') { // only android needs polyfill require('intl'); // import intl object require('intl/locale-data/jsonp/en-IN'); // load the required locale details } 

After completing the two steps above, you can get the locale string anywhere in your project using

 new Intl.NumberFormat('en-IN', { style: 'currency', currency: 'INR' }).format(10000000); 

If you need to format the number for another locale code, all the details of the locale code are available in intl/locale-data/jsonp/ . Just require the ones you need in your index.js file.

0
source

Source: https://habr.com/ru/post/1013663/


All Articles