0

My calculator is rounding to 2 decimal places. How do I change it to 3 decimal places?

    function formatDecimal(aFloat) {
        var digits = "" + Math.round(100 * aFloat);
        var length = digits.length;
        if (length < 3) {
            return "0." + digits;
        }
        else {
            var dp = length - 2;
            return digits.substring(0, dp) + "." + digits.substring(dp, length);
        }
    }

    //Return the char of aString at index.
    //If index is invalid, the results are undefined.
    function charAt(aString, index) {
        var length = aString.length;
        return aString.substring(index, index + 1);
    }

0 Answers0