Simply passing your number to the following function applies any zeros that are required.
Set the number of digits required at variable totalDigits and if a number has less than this value the appropriate number of zeros are added to the beginning of the number.
|
totalDigits=4
function addZeros(n){
num = n.toString()
if(isNaN(num)){ // check if number
return num
}
while(num.length < totalDigits){
num = '0'+num
}
return num
}
|
Original
|
4 digit format
|
Divide a whole number into set groups.
Coming Soon