-1

I am trying to build a finance calculator but I can't get the function correct.

At the moment I have:

function calculatepay() {
  var months =  $('#fin_months').val();
  var amount =  $('#fin_amount').val();
  var deposit =  $('#fin_deposit').val();
  var result =  Math.round((amount - deposit) / months).toFixed(2);
  $('#fin_result').val(result);
  $
}

It will calculate 1000 / 12 as 83.00 - it should be 83.33.

Can anyone help me figure it out

J Chia
  • 13
  • 1

1 Answers1

1

You can do 2 things:

  1. Remove Math.round and only us toFixed if you don't need rounding.

  2. Use Math.round((amount-deposit/months)*100)/100

So basically, Math.round((1000/12)*100)/100 will give you 83.33

aliasav
  • 3,048
  • 4
  • 25
  • 30