Pad a given number with leading zeroes. Useful to make it a fixed width like with e.g. sprintf
in other programming langages.
- Example:
00001
,00012
,00123
,01234
,12345
pad(number, count);
// returns number with leading zeros
See the 140byt.es site for a showcase of entries (built itself using 140-byte entries!), and follow @140bytes on Twitter. And check my "JavaScript Golf Lessons" slides.
I don't know much, but i believe it's because JavaScript uses the "double-precision 64-bit binary format IEEE 754 value" to repersent numbers, and it always causes such a problem.
Another typical problem:
0.1 + 0.2 = 0.30000000000000004
http://es5.github.com/#x8.5