I have this;
export const countDecimals = (value) => {
let num = parseFloat(value.replace(/,/g, ""));
if (Math.floor(num) === num) return 0;
return num.toString().split(".")[1].length || 0;
}
it works until I enter a number with trailing zero, such as 2.10. It ignores the zero and returns 1.
How to fix this?
P.S. Reason I am doing parseFloat is because in my case value is string and will be formatted if it is a large number like "2,190.10".