1const num1 = 1.123456789;
2const num2 = 123456789;
3const decimalCount = num => {
4 // Convert to String
5 const numStr = String(num);
6 // String Contains Decimal
7 if (numStr.includes('.')) {
8 return numStr.split('.')[1].length;
9 };
10 // String Does Not Contain Decimal
11 return 0;
12}
13console.log(decimalCount(num1)) // 9
14console.log(decimalCount(num2)) // 0