xxxxxxxxxx
function pad(num, size) {
num = num.toString();
while (num.length < size) num = "0" + num;
return num;
}
xxxxxxxxxx
const number = 5;
console.log(number.toString().padStart(2, '0')); // expected output: "05"
xxxxxxxxxx
function padLeadingZeros(num, size) {
var s = num+"";
while (s.length < size) s = "0" + s;
return s;
}
padLeadingZeros(57, 3);// "057"
padLeadingZeros(57, 4); //"0057"
xxxxxxxxxx
const str1 = '5';
console.log(str1.padStart(2, '0')); // expected output: "05"
xxxxxxxxxx
function checkTime(i) {
if (i<10) {i = "0" + i}; // add zero in front of numbers < 10
return i;
}