Contact: aviboots(AT)netvision.net.il
39,885 questions
51,811 answers
573 users
function LeftPadWithZeros(n, len) { let s = '' + n; while (s.length < len) { s = '0' + s; } return s; } console.log(LeftPadWithZeros(17493, 8)); /* run: 00017493 */
let n = 17493; // padStart(targetLength, padString) console.log(String(n).padStart(8, '0')); /* run: 00017493 */
function LeftPadWithChar(n, len, padch = '0') { n = n + ''; return n.length >= len ? n : new Array(len - n.length + 1).join(padch) + n; } let num = 17493; console.log(LeftPadWithChar(num , 8)); /* run: 00017493 */