Compound interest is the addition of interest to the principal sum of a loan or deposit. In other words, it's the interest calculated on the initial principal and also on the accumulated interest of previous periods.
Let's use it in a practical example:
Let's assume that Bella has saved $1,000.00 dollars from her allowances and then decides to make a fixed deposit at her local Bank who promised to pay her 10% annual interest rate in return, compounded annually, for using her money. If Bella had to leave that money at the Bank for two (2) years, at the end of period she would have saved around $1,210.00 dollars.
How we did it?:
We worked out the interest for the first period, added the result to the total, and then calculated the interest for the next period using the new total, and so on and so forth..., resulting in $1,210.00 dollars.
The formula for compound interest, including principal sum, is: A = P (1 + r/n)^(nt), as explained at The Calculator Site.
Please note that ^ means "to the power of", and if you were to use that code on the above formula, it should look as follows:
A = P * Math.pow((1 + (r/100)/n),(n*t)) or (P*Math.pow((1+(r/100)/n),(n*t)))
A = the future value of the investment/loan, including interest;
P = the principal investment amount (the initial deposit or loan amount);
r = the annual interest rate (decimal);
n = the number of times that interest is compounded per unit t;
t = the time the money is invested or borrowed for.
Please also note that I have divided r by a 100 so it may return the value (rate) in percentage.