js浮点数运算保留两位小数点

js浮点数运算保留两位小数点

window.onload = function() {
        a = 16601.56;
        b = 11482.00;
        function sum(a, b) {
            //.toFixed(4) 两位小数点
            return parseFloat(a - b).toFixed(2);
        }
        function sum1(a, b) {
            return parseFloat(a + b).toFixed(2);
        }

        console.log(sum(a,b)) // 1,234,567,890
        console.log(sum1(a,b)) // 1,234,567,890
    }

你可能感兴趣的:(javascript)