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

Number parser bug for en-IN (actually *-IN) #660

Closed
rxaviers opened this issue Dec 20, 2016 · 2 comments
Closed

Number parser bug for en-IN (actually *-IN) #660

rxaviers opened this issue Dec 20, 2016 · 2 comments
Labels

Comments

@rxaviers
Copy link
Member

rxaviers commented Dec 20, 2016

Reported via http://stackoverflow.com/questions/41221215/globalize-bug-in-new-v1-2-1-parsing-certain-numbers-returns-nan-for-17-cultures


With the new version 1.2.1 of Globalize we're seeing 17 cultures for which parsing fails for numbers in the "hundreds" range (e.g. between 100 and 999).

Here's a concrete example using the CLDR JSON data version 30.0.2 (also tested with the CLDR 30.0.3 data with the same results):

var g = new Globalize("en-IN");
g.numberParser()(g.numberFormatter()(1000.01)); // prints 1000.01
g.numberParser()(g.numberFormatter()(999.99)); // prints NaN

To the best of my knowledge, formatting the number 999.99 and then parsing it should not yield NaN, so this looks like a bug. NaN is also the result for the number 100, and indeed it seems like it's the result for any number with three significant digits.

If we just focus on the parsing step, we see the following:

var g = new Globalize("en-IN");
console.log(g.numberParser()("1,000.01")) // prints 1000.01
console.log(g.numberParser()("100.01")) // prints NaN

If we use the earlier Globalize code from version 1.1.2 then the behavior is correct (i.e. no NaN problems).

The 17 cultures in question are: as-IN,bn-BD,bn-IN,brx-IN,dz-BT,en-IN,gu-IN,hi-IN,kok-IN,ks-Arab-IN,ml-IN,mr-IN,or-IN,pa-IN,ta-IN,ta-LK,te-IN. Our unit tests picked them all up after we upgraded to Globalize 1.2.1.

We're wondering if somebody might be kind enough confirm that they can reproduce this (is there a jsfiddle template for doing this sort of thing?), and which change in the new version of Globalize (assuming it is a problem in Globalize) is causing this so that we can perhaps post a corresponding issue.

@rxaviers rxaviers added the bug label Dec 20, 2016
@rxaviers
Copy link
Member Author

The bug seems related to parsing a number that has 2nd grouping separator. parsing 1,000 works, but 1000 doesn't.

@rxaviers
Copy link
Member Author

Due to the same root cause, Globalize('en').parseNumber('1', {style: 'percent'}) was wrongly returning 1 instead of NaN.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant