1 2 3 4

四舍五入方法

getFloat = (num, n) => {
        n = n ? parseInt(n) : 0;
        if(n <= 0) {
          return Math.round(num);
        }
        num = Math.round(num * Math.pow(10, n)) / Math.pow(10, n); //四舍五入
        num = Number(num).toFixed(n); //补足位数
        return num;
      };
posted @ 2020-07-23 10:38  无序  阅读(146)  评论(0编辑  收藏  举报