Answers for "javascript padding number"

7

javascript print int with leading zeros

function padLeadingZeros(num, size) {
    var s = num+"";
    while (s.length < size) s = "0" + s;
    return s;
}
padLeadingZeros(57, 3);// "057"
padLeadingZeros(57, 4); //"0057"
Posted by: Guest on August-02-2019
0

string padStart padEnd

let string = ‘Alice’; 
// padStart() — we assume our string needs to have 10 characters 
string.padStart(10, ‘o’); // returns ‘oooooAlice’
// padEnd() 
string.padEnd(10, ‘o’); // returns ‘Aliceooooo’;
Posted by: Guest on November-26-2020

Code answers related to "Javascript"

Browse Popular Code Answers by Language