Over a million developers have joined DZone.

LeftZeroPad

·

var MANY_ZEROS = "000000000000000000";

function leftZeroPad(val, minLength) {
    if (typeof(val) != "string")
        val = String(val);
    return (MANY_ZEROS.substring(0, minLength - val.length)) + val;
}


leftZeroPad(3, 2) ==> "03"
Topics:

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}