Skip to content

Instantly share code, notes, and snippets.

@NextToNothing
NextToNothing / index.html
Created August 24, 2013 03:39
Testing different left padding techniques to find the most versatile and quickest method. For this Stack Overflow question: http://stackoverflow.com/questions/1267283/how-can-i-create-a-zerofilled-value-using-javascript
<script>
var theNum = 9;
var thePadNum = 2000;
// Jack B
function pad1(str, max, padder) {
padder = typeof pad1der === "undefined" ? "0" : padder;
return str.toString().length < max ? pad1(padder.toString() + str, max, padder) : str;
}