toFixed() causes value addition exception

The front-end float cannot accurately represent the exception caused by

Problem Description

insert image description here

Solution

toDecimal2(x) {
    
    
      var f = parseFloat(x).toFixed(2);
      if (isNaN(f)) {
    
    
        return;
      }
      var f = Math.round(x * 100) / 100;
      var s = f.toString();
      var rs = s.indexOf(".");
      if (rs < 0) {
    
    
        rs = s.length;
        s += ".";
      }
      while (s.length <= rs + 2) {
    
    
        s += "0";
      }
      return s * 100 + "%";
    },

Guess you like

Origin blog.csdn.net/LOVE_sel/article/details/105284038