HcpShadow / jquery-numberformatter

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

Can only enter 10-based percentages? #74

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
Hi,

Having an input field formatted '#%', it seems all input is 'rounded' to 
ten-based numbers, so 35% becomes 40% etc. The 'round' option doesn't help here.

My whole code is:

<code>
    $('.formatPercentage').blur(function(){
        var format = '#%';
        $(this).parseNumber({'format':format, 'locale':'nl', 'round': false});
        $(this).formatNumber({'format':format, 'locale':'nl', 'round': false});
    });
</code>

The issue seems to come from the end of the parseNumber function in the 
hasPercent test.

I've changed the last "number = number.toFixed(validText.length - 1);" 

to "number = number.toFixed(validText.length);" which seems to work  for me...

Original issue reported on code.google.com by macjo...@gmail.com on 14 Nov 2012 at 3:21

GoogleCodeExporter commented 8 years ago
Thanks for reporting. Yes this was a defect it seems, I fixed it a few days ago 
based on a previously reported issue with the parsing here, your fix is more or 
less it actually, I changed it to -

number = number.toFixed(2);

2 because I recall this is for % with no decimal point, so 35% in your case for 
example. So simply 2 is a nice enough precision to use as it will support >=1%.

Will be part of the next release.

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