Syafiqq / jquery-numberformatter

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

Percentages are parsed incorrectly #76

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Demo: http://jsfiddle.net/ebeTk/2/

Steps to reproduce:

1. Type "45%" into the input.
2. Blur (click away from the input).
3. Parse returns "0.5" and the input gets formatted as "50%".

Or:

1. Type ".45" into the input.
2. Blur.
3. The input's value will be parsed and formatted correctly.
4. Set focus to the input but do not change its value.
5. Blur again.
6. Parse returns "0.5" and the input gets formatted as "50%".

(The second case would be especially frustrating as percentages would get 
updated to incorrect values as a user tabbed through an interface.)

I'm using version 1.2.3 of the plugin in Chrome 24 on Windows 7.

The fix appears to be to change line 461 to "number = number.toFixed(2)" (to 
account for the fact that the number was divided by 100) but I'm not sure if 
that change would have a negative impact on any other functionality.

(My debugging leads me to believe that "45%" parses to 45, then is divided by 
100 to 0.45, but then the current version of line 461 rounds that to 0.5.)

Original issue reported on code.google.com by matthew....@gmail.com on 13 Mar 2013 at 9:04

GoogleCodeExporter commented 9 years ago
Hi, to me this does seem to work with 45% being parsed to 0.45 with both chrome 
and FF. I've also fixed some parsing of percentages with the upcoming release, 
so between them I hope you now get what you're looking for.

Am going to set this to unable to reproduce for now, please let me know if you 
continue to have issues and I'm happy to look into it further.

Original comment by apar...@gmail.com on 22 Oct 2013 at 9:34