Fnykis
5/7/2020 - 2:34 PM

Add zeroes before a number

String.prototype.repeat = function(x) {
    var str = "";
    for (var repeats = 0; repeats < x; repeats++) str = str + this;
    return str;
}
Number.prototype.digitsToString = function(digits) {
    if (this == 0) return ("0".repeat(digits));
    var dec = this / (Math.pow(10, digits));
    var str = dec.toString().substring(2, dec.toString().length);
    return str;
};