bcscale(20);
$balance = 1;
-$years = 100;
-$rate = 0.05;
+$years = 2017;
+$rate = 0.03;
$totalMonths = $years * 12;
print 'Invest ' . $balance . ' EUR and come back later.' . PHP_EOL;
for ($i = 1; $i <= $totalMonths; $i++) {
- if ($i % 12 == 0) {
- $rate = bcdiv($rate, 1.01);
- } // END - if
+ // Reduce interest rate every month
+ $rate = bcdiv($rate, 1.00001);
+ // Calculate interest
$interest = bcmul($balance, $rate);
+
+ // ... and add it to balance
$balance = bcadd($balance, $interest);
print 'Month ' . $i . ': rate=' . bcmul($rate, 100) . '%,interest=' . $interest . ',balance=' . $balance . PHP_EOL;
-} // END - foreach
+}
print 'After ' . $totalMonths . ' months (' . $years . ' years) you have ' . $balance . ' EUR back.' . PHP_EOL;
//print 'Length:' . strlen($balance) . PHP_EOL;
-
-?>