-4
$(document).ready(function() {
  $('select').on('change', function() {

    $('.total_result').text(

      $('select[name=attendance]').val() * 0.25 + $('select[name=tardiness]').val() * 0.10 + $('select[name=rules]').val() * 0.05 + $('select[name=case]').val() * 0.05 + $('select[name=productivity]').val() * 0.15 + $('select[name=qa]').val() * 0.15 + $('select[name=utilization]').val() * 0.05 + $('select[name=schedule]').val() * 0.05 + $('select[name=fcr]').val() * 0.10 + $('select[name=aht]').val() * 0.05)
    ;

  });

});

I have an issue with my final code. I need to round the decimal. I'm using onchange that will auto calculate. Much appreciated. TIA

jackflick
  • 53
  • 8

1 Answers1

0

.toFixed(2); method is Used to round value.

in you example it will be like

$(document).ready(function() {
  $('select').on('change', function() {

    $('.total_result').text(($('select[name=attendance]').val() * 0.25 + $('select[name=tardiness]').val() * 0.10 + $('select[name=rules]').val() * 0.05 + $('select[name=case]').val() * 0.05 + $('select[name=productivity]').val() * 0.15 + $('select[name=qa]').val() * 0.15 + $('select[name=utilization]').val() * 0.05 + $('select[name=schedule]').val() * 0.05 + $('select[name=fcr]').val() * 0.10 + $('select[name=aht]').val() * 0.05).toFixed(2));
  });
});

Reference LINK

Faraz
  • 644
  • 4
  • 13
  • @jackflick Try this – Faraz Mar 28 '18 at 04:46
  • .toFixed(2); accept a parameter, in this case 2, for Numbers after decimal. in case alert("123.456789".toFixed(3)); will alert "123.456" – Faraz Mar 28 '18 at 04:49
  • it worked Faraz! You're so amazing! I was trying the .toFixed(2) but it's not working for me and you did it just like that. :) Thank you very much! – jackflick Mar 28 '18 at 11:30