I have a number in Javascript, that I know is less than 10000 and also non-negative. I want to display it as a four-digit number, with leading zeroes. Is there anything more e
You could go crazy with methods like these:
function PadDigits(input, totalDigits)
{
var result = input;
if (totalDigits > input.length)
{
for (i=0; i < (totalDigits - input.length); i++)
{
result = '0' + result;
}
}
return result;
}
But it won't make life easier. C# has a method like PadLeft and PadRight in the String class, unfortunately Javascript doesn't have this functionality build-in