how to count the number of digits in a number in javascript code example
Example 1: digit count in javascript
function digitCount(num) {
if(num === 0 ) return 1
return Math.floor(Math.log10(Math.abs(num))) + 1
}
Example 2: javascript count digits
var length = (number + '').replace('.', '').replace('-', '').length; // for numbers that can be floats or negatives