为什么 onkeyup 的结果不同? (Javascript)

Why the result onkeyup is different? (Javascript)

我在下面有这些代码来计算最终分数。但是当我检查计算器时,结果是不同的。我可以知道为什么吗?

代码 :

function calculate() {
    var a = $("#sc1").val();
    var b = $("#sc2").val();
    var c = $("#sc3").val();
    scavg = (parseInt(a) + parseInt(b) + parseInt(c)) /3;
    scavg = scavg.toFixed(2);
    $("#scavg").val(scavg);
    var d = $("#scavg").val();
    var e = $("#np").val();
    f =  (parseInt(e)*3 + parseInt(d)*7) /10 
    $("input[name=na]").val(f);           
}

parseInt() return 整数,即整数。 scavg的格式是浮点数,如果你想显示小数到百位(.toFixed(2)),parseFloat()是你需要使用的。

演示

function calculate() {
  var a = $("#sc1").val();
  var b = $("#sc2").val();
  var c = $("#sc3").val();
  scavg = (parseFloat(a) + parseFloat(b) + parseFloat(c)) / 3;
  scavg = scavg.toFixed(2);
  $("#scavg").val(scavg);
  var d = $("#scavg").val();
  var e = $("#np").val();
  var f = (parseFloat(e) * 3 + parseFloat(d) * 7) / 10
  $("input[name=na]").val(f);
}

$('input').on('input', calculate);
input {
  font: inherit;
  display: block
}
<input id='sc1' type='number' step="0.01" placeholder='SC1'>
<input id='sc2' type='number' step="0.01" placeholder='SC2'>
<input id='sc3' type='number' step="0.01" placeholder='SC3'>
<input id='scavg' type='number' step="0.01" placeholder='scAvg'>
<input id='np' type='number' step="0.01" placeholder='NP'>
<input name='na' type='number' step="0.01" placeholder='NA'>


<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>