Perhaps some slight modifications to padnum:

return (Math.pow(10, (len || 2)) + val).toString().substr(1);

Using (len || 2) so the length can default to 2 if undefined (or zero); casting with toString because it’s faster; and use “substr” rather than “substring” because it takes fewer characters! (and is interchangeable in this case)

]]>function padnum(val, len)

{

return String(Math.pow(10,len)+val).substring(1);

}

It’s not as flexible as your function, and it obviously would need some bounds-checking, but for numbers about which you know the range of possibilities, it’s enough.

Even simpler, for well-known values like zero-padding a part of a date or time that we know is less than 100, use:

return String(100+val).substring(1);

thanks for any info.

]]>