yeelliott / jquery-utils

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

$.format doesn't pad digits correctly. #58

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. run: $.format('{0:03d}', 2)
2. then run: $.format('{0:03d}', 10)

The expected output would be '002' and '010' as when I run '{0:03d}'.format(2) 
and '{0:03d}'.format(10) in Python 2.6. This is not the case, what I get is 
'002' and '0010'.

I am running "jQuery utils - 0.8.5" on Windows 7, Google Chrome 7.0.517.44

Original issue reported on code.google.com by c.fre...@gmail.com on 23 Nov 2010 at 1:35

GoogleCodeExporter commented 9 years ago
I simplified the '__pad' function and removed the 't' parameter which I could't 
find any usage of in the rest of the code any way.

Code:

__pad: function(str, l, s){
    var p = s || ' ';
    var o = str;
    if (l - str.length > 0) {
        o = new Array(Math.ceil(l / p.length)).join(p).substr(0, l-str.length) + str;
    }
    return o;
}

Original comment by c.fre...@gmail.com on 23 Nov 2010 at 2:17