Rounding issue in Math.round() & .toFixed()

前端 未结 7 1094
半阙折子戏
半阙折子戏 2020-12-10 16:58

I used below two methods :

Number.prototype.myRound = function (decimalPlaces) {
    var multiplier = Math.pow(10, decimalPlaces);

    return (Math.round(th         


        
相关标签:
7条回答
  • 2020-12-10 17:50

    Just use Math.round

    function round(figureToRound){
        var roundOff = Math.round((figureToRound* 100 ).toFixed(2))/100;
        return roundOff;
    }
    
    console.log(round(1.005));
    

    This will help the rounding off issue completely.

    0 讨论(0)
提交回复
热议问题