Javascript Math.max不返回正在比较的任何一个数字

Javascript Math.max不返回正在比较的任何一个数字,javascript,math,Javascript,Math,下面是我试图在jQuery应用程序中使用的一个简单的Math.max语句,以及调用的方法 guaranteedEoy: function() { return this.fixedAllocation() * (1 + (this.attributes.fixedRate / 100)) * Math.pow(1, 6); }, contractVal: function (value) { value = parseFloat(valu

下面是我试图在jQuery应用程序中使用的一个简单的
Math.max
语句,以及调用的方法

    guaranteedEoy: function() {
        return this.fixedAllocation() * (1 + (this.attributes.fixedRate / 100)) * Math.pow(1, 6);
    },

    contractVal: function (value) {
        value = parseFloat(value).toFixed(2);
        console.log(value);
        console.log(this.guaranteedEoy());
        console.log(parseFloat(this.guaranteedEoy()) + parseFloat(value));
        console.log(this.attributes.purchasePayment * Math.pow(1.01, 7));
        console.log(Math.max((this.attributes.purchasePayment * Math.pow(1.01, 7)), (this.guaranteedEoy() + value)));
        console.log('   ');
        return Math.max((this.attributes.purchasePayment * Math.pow(1.01, 7)), (this.guaranteedEoy() + value));
    },
我把
console.log
语句放在那里,因为从
Math.max
函数返回的数字比它应该比较的任何一个数字都要大。下面是上面控制台读数的屏幕打印图:

为了简化,这里是每个控制台读数对应的值

Value: 64000.00
this.guaranteedEoy(): 37008
this.guaranteedEoy() + value: 101008
this.attributes.purchasePayment * Math.pow(1.01, 7): 107213.53521070098
Math.max((this.attributes.purchasePayment * Math.pow(1.01, 7)), (this.guaranteedEoy() + value)): 370086400
因此基本上,
Math.max
语句读取

Math.max(107213.53521070098, 101008)

但是由于某些原因,它返回的值为
37086400

37086400
是所述值
37008
64000
的串联

应该是:

console.log(Math.max((this.attributes.purchasePayment * Math.pow(1.01, 7)),
        (parseFloat(this.guaranteedEoy()) + parseFloat(value))));
再次使用
parseFloat
以避免字符串连接(发生)


编辑:看起来
是字符串(由于
.toFixed()
),而
此.guarantedeoy()
返回数字。因此,有可能只对
value
使用
parseFloat
就足够了

37086400
是所述值
37008
64000
的串联

应该是:

console.log(Math.max((this.attributes.purchasePayment * Math.pow(1.01, 7)),
        (parseFloat(this.guaranteedEoy()) + parseFloat(value))));
再次使用
parseFloat
以避免字符串连接(发生)


编辑:看起来
是字符串(由于
.toFixed()
),而
此.guarantedeoy()
返回数字。因此,有可能只对
value
使用
parseFloat
就足够了

toFixed
返回一个字符串,因此
this.guarantedeoy()+value
执行字符串连接。如果只想将值四舍五入到小数点后两位,请参阅。

toFixed
返回一个字符串,因此
此.guarantedeoy()+value
执行字符串连接。如果只想将值四舍五入到小数点后两位,请参阅。

toFixed
返回字符串。你为什么还要用它?您只是想对值进行四舍五入吗?这个问题似乎与jQuery
toFixed
返回字符串无关。你为什么还要用它?您只是想对值进行四舍五入吗?这个问题似乎与jQuery没有任何关系