• Counts the number of decimal places in a number.

    Parameters

    • n: number

      The number to analyze.

    Returns number

    • The number of digits after the decimal point, or 0 if the number is an integer, has no decimal part, or is not a finite number (e.g., NaN, Infinity).

    countDecimals

    console.log(countDecimals(123.45));    // Outputs: 2
    console.log(countDecimals(10)); // Outputs: 0
    console.log(countDecimals(5.0)); // Outputs: 0
    console.log(countDecimals(3.14159)); // Outputs: 5
    console.log(countDecimals(NaN)); // Outputs: 0
    console.log(countDecimals(Infinity)); // Outputs: 0
MMNEPVFCICPMFPCPTTAAATR