js number 2 decimal places
(3.141596).toFixed(2); // 3.14
how count decimals javascript
const num1 = 1.123456789;
const num2 = 123456789;
const decimalCount = num => {
// Convert to String
const numStr = String(num);
// String Contains Decimal
if (numStr.includes('.')) {
return numStr.split('.')[1].length;
};
// String Does Not Contain Decimal
return 0;
}
console.log(decimalCount(num1)) // 9
console.log(decimalCount(num2)) // 0
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us