var countDecimals = function (value) { 
    if ((value % 1) != 0) 
        return value.toString().split(".")[1].length;  
    return 0;
};

Example

countDecimals(2.00001)//5
countDecimals(2.00000)//5
Last modified: 18/10/2023

Author

Comments

Write a Reply or Comment

Your email address will not be published.