Added calculation scripts (I know, they might be wrong) + moved some files and
[core.git] / contrib / exp / exp2.php
1 <?php
2 error_reporting(E_ALL | E_STRICT);
3
4 bcscale(20);
5
6 $balance = 1;
7 $years = 100;
8 $rate = 0.05;
9
10 $totalMonths = $years * 12;
11
12 print 'Invest ' . $balance . ' EUR and come back later.' . PHP_EOL;
13
14 for ($i = 1; $i <= $totalMonths; $i++) {
15         if ($i % 12 == 0) {
16                 $rate = bcdiv($rate, 1.01);
17         } // END - if
18
19         $interest = bcmul($balance, $rate);
20         $balance = bcadd($balance, $interest);
21
22         print 'Month ' . $i . ': rate=' . bcmul($rate, 100) . '%,interest=' . $interest . ',balance=' . $balance . PHP_EOL;
23 } // END - foreach
24
25 print 'After ' . $totalMonths . ' months (' . $years . ' years) you have ' . $balance . ' EUR back.' . PHP_EOL;
26 //print 'Length:' . strlen($balance) . PHP_EOL;
27
28 ?>