JavaScript panjang angka
x.toString().length // x is a number
Clumsy Cicada
x.toString().length // x is a number
var number = 773;
number.toString().length;
var num = 1234
number.toString().length; // 4
let a = 123
// changing to string
console.log(`${a}`.length) // 3
// without changing to string
Math.ceil(Math.log(a + 1) / Math.LN10) // 3
export function numberLength(number) {
let length = 0;
let n = Math.abs(number);
do {
n /= 10;
length++;
} while (n >= 1);
return length;
}
export default numberLength;