Web Analytics Made Easy -
StatCounter interest rate calculator - CodingForum

Announcement

Collapse
No announcement yet.

interest rate calculator

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • interest rate calculator

    I am trying to create a calculator that allows the user to enter a balance amount, the interest rate and the payment. I want the calculator to figure and write the amount that went to interest and the amount that went to the balance. My biggest problem is that I need the two calculations to stop after two decimals. I can't figure it out.

    The calculator can be found at costofcredit.com/interest_paid.html

    Thanks for any help.

  • #2
    For the decimal you can use this:

    tmp = 345.2342355;
    tmp2 = Math.floor(tmp*100)/100;

    results:

    tmp2 = 345.23

    Comment


    • #3
      Thanks for replying. Can you help me with the code I wrote. My problem is that I can't figure out how to write the code with a undefined value. Here's my code:


      <script language="Javascript">

      <!-- begin

      function checkNumber(input, min, max, msg)
      {msg = msg + "Invalid data: " + input.value;
      var str = input.value;
      for (var i = 0; i<str.length;i++)

      {var ch = str.substring(i, i + 1)
      if((ch<"0" || "9"<ch)&& ch!=".")
      {alert(msg); return false;}
      }

      var num = parseFloat(str)
      if(num<min || max<num)
      {alert(msg + "not in range[" + min +".." + max +"]"); return false;}

      input.value = str; return true;
      }

      function computeField(input)
      {if (input.value !=null && input.value.length !=0)
      input.value="" + eval(input.value);
      computeForm(input.form);
      }

      function computeForm(form)
      {if ( (form.balance.value==null || form.balance.value.length==0) ||
      (form.interest.value==null || form.interest.value.length==0) ||
      (form.payment.value==null || form.payment.value.length==0)
      )
      {return;}

      if ( !checkNumber(form.balance, 1, 100000, "Balance") ||
      !checkNumber(form.interest, .001, 99, "Interest") ||
      !checkNumber(form.payment, 10, 100000, "Payment")
      )
      {form.interestpaid.value = "Invalid"; return;}

      var i= form.interest.value;
      if(i > 1.0)
      {i = i / 100.0; form.interest.value = i;}


      i /=12;
      money = (form.balance.value * i * 1.00);
      form.interestpaid.value = money;
      applied = (form.payment.value - money);
      form.appliedtobalance.value = applied;
      }

      function clearForm(form)
      {form.balance.value = "";
      form.interest.value = "";
      form.payment.value = "";
      }

      //done hiding from old browsers-->
      </script>

      Comment

      Working...
      X