[removed] Comparing two float values

前端 未结 4 1801
忘了有多久
忘了有多久 2020-12-09 01:55

I have this JavaScript function:

Contrl.prototype.EvaluateStatement = function(acVal, cfVal) {

    var cv = parseFloat(cfVal).toFixed(2);
    var av = parse         


        
4条回答
  •  猫巷女王i
    2020-12-09 02:50

    toFixed returns a string, and you are comparing the two resulting strings. Lexically, the 1 in 12 comes before the 7 so 12 < 7.

    I guess you want to compare something like:

    (Math.round(parseFloat(acVal)*100)/100)
    

    which rounds to two decimals

提交回复
热议问题