Javascript Number zeropad(n)
Number.prototype.zeropad = function(n) { var str = "" + this; var len = n - str.length; var pad = ""; while (len-- > 0) { pad += "0"; }/* w ww . j av a 2s . c o m*/ return pad + str; };