Tuesday, June 11, 2019

Integer value with leading zero using JavaScript



prefix_zero(10,4) // output 0010

function prefix_zero(num, size) {
    var s = num+"";
    while (s.length < size) s = "0" + s;
    return s;
}


No comments:

Post a Comment

Your feedback is always appreciated. I will try to reply to your queries as soon as time allows.Please don't spam,spam comments will be deleted upon reviews.