Syafiqq / jquery-numberformatter

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

Bug in truncating mode #56

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Use a pattern with decimals (i.e. #,###.00 or #,###.##). 
2. Set options.round = false;
3. Format a number with no decimals: 2233

What is the expected output? What do you see instead?
Expected: 2233.00 or 2233
Received: 22.00 or 22

What version of the product are you using? On what operating system?
1.2.2

Please provide any additional information below.
Issue in line 286:
            // round or truncate number as needed
            if (options.round == true)
                number = new Number(number.toFixed(decimalFormat.length));
            else {
                var numStr = number.toString();
                numStr = numStr.substring(0, numStr.lastIndexOf('.') + decimalFormat.length + 1);
                number = new Number(numStr);
            }
====
Add check for ".": if(numStr.lastIndexOf('.')>0)

            // round or truncate number as needed
            if (options.round == true)
                number = new Number(number.toFixed(decimalFormat.length));
            else {
                var numStr = number.toString();
                if(numStr.lastIndexOf('.')>0)
                    numStr = numStr.substring(0, numStr.lastIndexOf('.') + decimalFormat.length + 1);
                number = new Number(numStr);
            }

Original issue reported on code.google.com by discover...@gmail.com on 13 Oct 2011 at 3:29

GoogleCodeExporter commented 9 years ago
Fixed, thanks for the code, will go into next release.

Original comment by apar...@gmail.com on 18 Oct 2013 at 11:09