wvmoreira / jquery-numberformatter

Automatically exported from code.google.com/p/jquery-numberformatter
0 stars 0 forks source link

Bug parsing percentages with no decimals #66

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
This code 

$.parseNumber("23%", { locale: "us" })

returns 0.2 when it should return 0.23. 

The issue is fixed by changing line 461 from 

number = number.toFixed(validText.length - 1);

to 

number = number.toFixed(validText.length);

Original issue reported on code.google.com by h...@caudillweb.com on 3 Jul 2012 at 5:14

GoogleCodeExporter commented 8 years ago
[deleted comment]
GoogleCodeExporter commented 8 years ago
My fix actually doesn't work with single digit percentages - 

$.parseNumber("2%", { locale: "us" })

returns 0 when it should return 0.02.

I've just commented out lines 456-462 for now - for me there's no utility in 
truncating to a fixed number of digits.

Original comment by h...@caudillweb.com on 3 Jul 2012 at 6:21

GoogleCodeExporter commented 8 years ago
Yup it's a defect, I changed

number = number.toFixed(validText.length - 1);
->
number = number.toFixed(2);

and that seems to resolve it. Will be included in the next release.

Original comment by apar...@gmail.com on 18 Oct 2013 at 1:02