Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

toLocaleString is only working on ios not android. #15717

Closed
hyochan35 opened this issue Aug 31, 2017 · 29 comments
Closed

toLocaleString is only working on ios not android. #15717

hyochan35 opened this issue Aug 31, 2017 · 29 comments
Labels
Resolution: Locked This issue was locked by the bot.

Comments

@hyochan35
Copy link

toLocaleString is only working on ios and not android.

When will this be supported?

@hramos
Copy link
Contributor

hramos commented Aug 31, 2017

Hey, thanks for reporting this issue!

It looks like your description is missing some necessary information, or the list of reproduction steps is not complete. Can you please add all the details specified in the template? This is necessary for people to be able to understand and reproduce the issue being reported.

I am going to close this, but feel free to open a new issue with the additional information provided. Thanks!

@hramos hramos closed this as completed Aug 31, 2017
@hsavit1
Copy link

hsavit1 commented Sep 12, 2017

Dude, there's no missing information. toLocaleString() is a Javascript number formatting string method that just doesn't work at all on android. Please fix this

@hanishsharma
Copy link

Hi all, I am also facing the same issue in Android although it is working fine in iOS.

@ferdicus
Copy link
Contributor

I've noticed, that .toLocaleString does weirdly only work in JS Debug Mode on Android

@hyochan
Copy link
Contributor

hyochan commented Nov 1, 2017

Any update?

@hamidfzm
Copy link

hamidfzm commented Nov 4, 2017

I'm using version 0.47.1 of react-native. Using number.toLocaleString('fa') works perfectly in iOS but not in android.

@ghost
Copy link

ghost commented Nov 8, 2017

Hi all, I am also experiencing this issue on android although it works fine in IOS.

@apbeers
Copy link

apbeers commented Nov 15, 2017

I have the same issue. Works fine on iOS but not Android. On Android the Expo app on the device will crash when I try to call it

@WaldoJeffers
Copy link
Contributor

This should be re-opened @hramos , this is a real bug.

@tzig
Copy link

tzig commented Dec 21, 2017

Same here, work fine on iOS and only in debug-mode on Android. Any workaround for the meantime?

@hamidfzm
Copy link

hamidfzm commented Dec 24, 2017

@tzig You can try using react-native-globalize if you don't mind using an extra library in your app.

@gfviegas
Copy link

This issue was so terribly closed, such an easy to see bug and they still want us to create templates to show that a simple JS function wont work on a specific OS.... terrible.

I'm on react native 0.50.3 and I got the same issue

@hamidfzm
Copy link

There is an other open issue for this bug with their prefered template: #16867. Hope they don't close it.

@abhandaru
Copy link

Same issue. Not very reassuring that the RN team will address this.
What work-arounds have people been using?

@outofcoffee
Copy link

@abhandaru I've been using https://github.com/smirzaei/currency-formatter for currencies, which works well on iOS and Android.

@hjpsievert
Copy link

I had the same problem on Android; using toLocaleDateString() instead seems to work. Since I only was interested in the date part and not the time part, that was enough for me. I would assume, though, that for complete date and time results a combination of toLocaleDateString() and toLocaleTimeString() would work

@ccdwyer
Copy link

ccdwyer commented Mar 13, 2018

This is an issue still, with numbers:
https://imgur.com/xCLWo16

They are formatting correctly in iOS, not in Android.

@Culzean
Copy link

Culzean commented May 8, 2018

@ferdicus this is likely due to the JavaScript engine being used. Normally RN will use JavaScriptCore. However while debugging under chrome debugging, it has to use V8. Though I thought JavaScriptCore supported this feature. So there must be more to this puzzle.

This issue being closed looks silly. Is this resolved in RN 0.55.3?

@naytun
Copy link

naytun commented May 19, 2018

Work around solution is:
number.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",")

@jpdriver
Copy link
Contributor

☝️ I opened a new issue for this and sacrificed a small goat to the template gods 😬

@brunooojapa
Copy link

brunooojapa commented Jun 7, 2018

In my way that solve this problem was this, I hope to help:

var today = new Date();
var dd = today.getDate();
var mm = today.getMonth()+1; //January is 0!
var yyyy = today.getFullYear();
if(dd<10)
{dd='0'+dd}
if(mm<10)
{mm='0'+mm}
var today = dd+'/'+mm+'/'+yyyy;
console.log(today)
console.log('blackMagic')
return today; // dd/mm/yyyy

@AlirezaAkbarix
Copy link

It's a real shame, to those who are using toLocaleString() method for Currency you can use this code for now:

`
_getPriceValue() {

if (Platform.OS === 'ios')

  return (+this.props.number).toLocaleString(fa ? 'fa-IR' : 'en-US', {maximumFractionDigits: 0});

else

  return (+this.props.number).toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");

}
`

@mths0x5f
Copy link

mths0x5f commented Jul 9, 2018

Shameful.

@th-m
Copy link

th-m commented Jul 15, 2018

Here is the workaround I use. toLocaleTimeString() returns military time, so it is easy enough to convert from there.

    formatStandardTime = date => {
        let time = date.toLocaleTimeString();
        time = time.split(':'); // convert to array

        // fetch
        var hours = Number(time[0]);
        var minutes = Number(time[1]);
        var seconds = Number(time[2]);

        // calculate
        var timeValue;

        if (hours > 0 && hours <= 12) {
        timeValue= "" + hours;
        } else if (hours > 12) {
        timeValue= "" + (hours - 12);
        } else if (hours == 0) {
        timeValue= "12";
        }
        
        timeValue += (minutes < 10) ? ":0" + minutes : ":" + minutes;  // get minutes
        timeValue += (seconds < 10) ? ":0" + seconds : ":" + seconds;  // get seconds
        timeValue += (hours >= 12) ? " P.M." : " A.M.";  // get AM/PM
        return timeValue
    }

stack overflow code source

@luco
Copy link

luco commented Jul 24, 2018

Still having this.

@nahoang
Copy link

nahoang commented Jul 31, 2018

Still face with this problem. it's only work in debug mode. it's too weird

@AlirezaAkbarix
Copy link

AlirezaAkbarix commented Jul 31, 2018

Guys it's clear it still exists! cause there is no new release and also no one is taking care about this thread :|

So don't repeat this message please.

@jpdriver
Copy link
Contributor

The root cause here is the outdated JSC runtime that React Native Android ships with.

It isn't something that can be easily patched; so there isn't going to be a PR specifically for this -- but there is a wider discussion around migrating to either a newer JSC version or allowing users to bundle any arbitrary JSC here.

If and when the JSC ever gets updated, this should work as expected on both platforms. But until then, you have two options.

  1. polyfill it yourself

  2. (the hardcore route) use the JSC buildscripts repo to compile a newer version and bundle it into your app.

⚠️ The JSC is a fairly core piece of the Android architecture though; so proceed at your own risk

Unless you fully understand the implications of replacing it with your own version, I'd recommend sticking to option 1.

@SilencerWeb
Copy link

still not fixed, hehe, niiiiiiice

@facebook facebook locked as resolved and limited conversation to collaborators Aug 31, 2018
@react-native-bot react-native-bot added the Resolution: Locked This issue was locked by the bot. label Aug 31, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Resolution: Locked This issue was locked by the bot.
Projects
None yet
Development

No branches or pull requests