解决四舍五入不准确问题

  • Post author:
  • Post category:其他


  this.sum = this.form.namea * ((100 - this.form.nameb) * 0.01);
      if (
        this.sum.toString().split(".") &&
        this.sum.toString().split(".")[1] &&
        this.sum.toString().split(".")[1].length > 2
      ) {
      
        if (this.sum.toString().split(".")[1].charAt(2) * 1 === 5) {
          const newNumber = Number(
            this.sum.toString().split(".")[0] +
              "." +
              this.sum.toString().split(".")[1] +
              "1"
          );
          this.sum = newNumber.toFixed(2);
        } else {
          this.sum = this.sum.toFixed(2);
        }
      }



版权声明:本文为m0_71792040原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。