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
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