Why is my toFixed() function not working?

前端 未结 5 1325
悲哀的现实
悲哀的现实 2020-12-29 17:49

Here\'s the relevant code. I\'ve confirmed with the alert that the correct number is saved, it\'s just not being changed to 2 decimal places.

if ($(this).a         


        
5条回答
  •  甜味超标
    2020-12-29 18:28

    document.getElementById("EDTVALOR").addEventListener("change", function() {
      this.value = this.value.replace(",", ".");
      this.value = parseFloat(this.value).toFixed(2);
      if (this.value < 0) {
        this.value = 0;
      }
      this.value = this.value.replace(".", ",");
      this.value = this.value.replace("NaN", "0");
    });
    

提交回复
热议问题