Why is my toFixed() function not working?

前端 未结 5 1315
悲哀的现实
悲哀的现实 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:20

    Example simple (worked):

    var a=Number.parseFloat($("#budget_project").val()); // from input field
    var b=Number.parseFloat(html); // from ajax
    var c=a-b;
    $("#result").html(c.toFixed(2)); // put to id='result' (div or others)
    

提交回复
热议问题