leftZeroPad
1 2 var MANY_ZEROS = "000000000000000000"; 3 4 function leftZeroPad(val, minLength) { 5 if (typeof(val) != "string") 6 val = String(val); 7 return (MANY_ZEROS.substring(0, minLength - val.length)) + val; 8 }
leftZeroPad(3, 2) ==> "03"
DZone Snippets > steveyen > formatting
12729 users tagging and storing useful source code snippets
Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world
Steve Yen trimpath.com
1 2 var MANY_ZEROS = "000000000000000000"; 3 4 function leftZeroPad(val, minLength) { 5 if (typeof(val) != "string") 6 val = String(val); 7 return (MANY_ZEROS.substring(0, minLength - val.length)) + val; 8 }