count the number of digits in a number code example
Example 1: find number of digits in a number
floor(log10(n) + 1);
Example 2: c how many digits has a number
digits = (number == 0) ? 1 : (log10(number) + 1);
//or
while (number > 0)
{
number /= 10;
digits++;
}
//see: https://ideone.com/P1h8Ne
Example 3: get number of digits in a number
function getlength(number) {
return number.toString().length;
}