locbet / jquery-numberformatter

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

Feature request: option for formatting %'s without multiplication/division #50

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. Type '1.15' in a field
1. Run formatNumber({format:"#,##0.##%", locale:"us"}) on the field

What is the expected output? What do you see instead?
If the field is labeled as a percentage and is showing a default of, say, 
"1.25%", expected result might be "1.15%", but instead it is "115%"

What version of the product are you using? On what operating system?
1.2.2, Mac OS X 10.6.8

Please provide any additional information below.
Sometimes, if a field is marked as a percentage and is showing a percentage 
value, users will expect to be able to type in a similar value and simply omit 
the % sign. I'm working around this by first adding "%" to the number if it 
doesn't already have it, before parsing/formatting it.

Original issue reported on code.google.com by darwinca...@gmail.com on 29 Aug 2011 at 5:37

GoogleCodeExporter commented 8 years ago
This seems to be a problem that you want to parse a field into a percentage 
formatable number but not include the percentage sign sometimes (e.g. 1.15 -> 
0.0115). I suggest if you do not need real percentage support simply add/remove 
the % sign your side and do not use % in the format options, might make things 
easier for you.

I've fixed this issue by added the 'isPercentage' option to the parse method, 
so if it's set to true then it's always taken as a percentage, regardless of if 
it ends with % or not. I think this solves your problem officially rather than 
a work around.

I realise now that the percentage support was not fully joined-up on the 
parsing and formatting method, so real-world usage was always going to be a 
problem. Hopefully this is now much easier to work with.

Examples -

1.15
$('div').parseNumber({locale:"us", isPercentage: true});
$('div').formatNumber({format:"#.##%", locale:"us"});
=1.15%

3.21%
$('div').parseNumber({locale:"us", isPercentage: true});
$('div').formatNumber({format:"#.##%", locale:"us"});
=3.21%

Fixed as of r18 and will be released with 1.2.3.

Original comment by apar...@gmail.com on 5 Feb 2012 at 2:08

GoogleCodeExporter commented 8 years ago
This issue was closed by revision r18.

Original comment by apar...@gmail.com on 5 Feb 2012 at 2:08