Calculating future value with compound interest with JavaScript

后端 未结 6 1565
悲哀的现实
悲哀的现实 2021-02-04 19:39

I\'m trying to work on a script where the user inserts a monthly income and gets the future value with compound interest after 30 years. As it is now, I\'ve assigned some values

6条回答
  •  走了就别回头了
    2021-02-04 20:18

    Below is the code to calculate compound interest.

    function calculate() {
      p = document.getElementById("p").value;
      n = document.getElementById("n").value; // no. of compoundings per year
      t = document.getElementById("t").value; // no. of years
      r = document.getElementById("r").value;
      result = document.getElementById("result");
    
      // The equation is A = p * [[1 + (r/n)] ^ nt]
      A = (p * Math.pow((1 + (r / (n * 100))), (n * t)));
    
      // toFixed is used for rounding the amount with two decimal places.
      result.innerHTML = "The total amount is " + A.toFixed(2);
    
      result.innerHTML += "
    The interest is " + (A.toFixed(2) - p).toFixed(2); }
    div {
      display: table-row;
    }
    
    label,
    input {
      display: table-cell;
    }
    
    
    
      Compound Interest Calculation using jQuery
    
    
      

    Compound Interest Calculation Using jQuery

提交回复
热议问题