Answers for "count digits in a number javascript"

2

count the total number of digits of a number in javascript

const count = n => String((Math.abs(n))).length;

count(123); // ➞ 3
count(-45678); // ➞ 5
count(8912); // ➞ 4
Posted by: Guest on April-22-2021
2

javascript count digits

var length = (number + '').replace('.', '').replace('-', '').length;  // for numbers that can be floats or negatives
Posted by: Guest on August-21-2020
0

get number right of the dot length javascript

var x = 23.453453453;
x.countDecimals(); // 9

var countDecimals = function (value) {
    if(Math.floor(value) === value) return 0;
    return value.toString().split(".")[1].length || 0; 
}
Posted by: Guest on June-16-2020

Code answers related to "count digits in a number javascript"

Code answers related to "Javascript"

Browse Popular Code Answers by Language