The interest rate banks pay is usually a yearly percentage. So, if your bank tells you that you're getting *4%* interest and you start with *$20,000* in your account, you would earn an extra *$800* at the end of the year (*$20,000 x 0.04 = $800*).

However, it's not that simple. The interest you earn is usually compounded daily and paid monthly. This means the interest you earn on one day will be added to your original balance, which in turn earns interest the next day.

To calculate this, we take the *$800* from above and divide it by *365* to figure out how much interest you would earn the first day (*$800 / 365 = $2.19*). So, you would earn *$2.19* in interest on the first day. This *$2.19* is then added to your original balance (*$20,000 + $2.19 = $20,002.19*). Remember when I said the bank pays you monthly? This means that this new balance of *$20,002.19* is used in the calculation for tomorrow's interest however you won't actually get the money in your account until the end of the month. All this means is the bank doesn't have to put a couple dollars into your account every single day. You're still getting the same amount of money.

To calculate the interest earned the next day, you would do the same calculation but with the new balance (*$20,0002.19 x 0.04 / 365*). Can you see how your interest earned will increase each day? That's the beauty of compound interest.

In this case, the interest you would earn in 1 year is not *$800* like in our original calculation. The amount of interest you would actually earn is *$816.17*.

// Change these values $original_deposit = 4000; $interest_rate = 2.0; // Percent $number_of_years = 1; // Initializations $total = $original_deposit; $earned_interest = 0; // Loop through each day for ($i = 0; $i < ($number_of_years * 365); $i++) { // Find today's interest, which will be added to the total // This is where compound interest takes place // This means interest earned each day in turn earns interest :) $todays_interest = ($total * ($interest_rate / 100)) / 365; $total += $todays_interest; // For outputting stats only; not use in calculation $earned_interest += $todays_interest; } // Output stats echo "Interest rate: $interest_rate%\n"; echo "Number of years: $number_of_years\n\n";

You need to login to post a comment.