js计算精度不准问题

  computed: {
      hasNum() {
        return this.orderList.reduce((res, cur) => {
          res += (cur.amount||0)/100
          return this.formatNum(res,2)
        }, 0)
      }
    },


 formatNum(f, digit) { 
        var m = Math.pow(10, digit); 
        return parseInt(f * m, 10) / m; 
      },

  

posted @ 2021-04-08 14:47  小灬壊  阅读(134)  评论(0编辑  收藏  举报