.toFixed not for .0*

前端 未结 3 1626
轻奢々
轻奢々 2020-12-25 12:17

I have a few values:

var one = 1.0000
var two = 1.1000
var three = 1.1200
var four = 1.1230

and function:

function tofixed(         


        
3条回答
  •  独厮守ぢ
    2020-12-25 12:52

    The "correct" way to do it is as follows:

    return Math.round(num*100)/100;
    

    If you want to truncate it to two decimal places (ie. 1.238 goes to 1.23 instead of 1.24), use floor instead of round.

提交回复
热议问题