Wednesday, December 28, 2016

Pad a number with leading zeros

function pad(num, size) {
        var s = num + "";
        while (s.length < size) s = "0" + s;
        return s;
    }
pad(15, 4); // 0015
 
@reference_1_stackoverflow 
@reference_2_stackoverflow

No comments:

Post a Comment