Number.prototype.pad = function(length) { var res = this.toString(); var nulls = '00000000000000'; return nulls.substr(0, length - res.length) + res; };