If somebody knows how this works...I will worship you forever!
A person invests $1,000 in a saving account yielding 5% interest. Assuming that all interest is left on deposit, calculate and display the amount of money in the account at the end of each year for 10 years. Use the following formula for determining these amounts:
a = p(1 + r)n
p is the principal (original) amount invested,
r is the annual interest rate,
n is the number of years and
a is the amount on deposit at the end of the nth year.
amount = principal * Math.pow(1.0 + rate, year);
Math.round(amount * 100)/100
to format your numbers. This expression multiplies the current value of amount by 100 to convert the value from dollars to cents, then uses the Math object's round method to round the value to the closest integer. The result is then divided by 100, to produce a dollar value that has a maximum of 2 digits to the right of the decimal point.