kalkulyatorda kredit müddəti illik olaraq daxil edilir. Bunu aylıq etmək üçün hansı dəyişiklik edilməlidir ?
Yəni boş xanaya 1 yox, 12 yazılanda 12 aylıq göstərməsini istəyirəm
<?php $period = 12; function calculateMortgage($balance,$rate,$term){ global $period; $N = $term * $period; $I = ($rate/100)/$period; $v = pow((1+$I),$N); $t = ($I*$v)/($v-1); $result = $balance*$t; return $result; } $balance = isset($_POST['balance']) ? $_POST['balance'] : ''; $rate = isset($_POST['rate']) ? $_POST['rate'] : ''; $term = isset($_POST['term']) ? $_POST['term'] : ''; ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "DTD/xhtml1-transitional.dtd"> <html> <head> <title>Mortgage Payment Calculator</title> <link href="style/style.css" rel="stylesheet" type="text/css" /> </head> <body> <div id="main"> <div class="caption">Mortgage Payment Calculator</div> <div id="icon"> </div> <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" > <table width="100%"> <tr><td>Loan balance:</td><td><input class="text" name="balance" type="text" size="15" value="<?php echo $balance; ?>" /> $</td></tr> <tr><td>Interest rate:</td><td> <input class="text" name="rate" type="text" size="5" value="<?php echo $rate; ?>" /> %</td></tr> <tr><td>Loan term:</td><td> <input class="text" name="term" type="text" size="5" value="<?php echo $term; ?>" /> years</td></tr> <tr><td align="center" colspan="2"><br/><input class="text" type="submit" name="submitBtn" value="Calculate" /></td></tr> </table> </form> <?php if ((isset($_POST['submitBtn']) && ($balance != '') && ($rate != '') && ($term != ''))){ ?> <div class="caption">RESULT:</div> <div id="icon2"> </div> <div id="result"> <table width="100%"> <?php $pay = round(calculateMortgage($balance,$rate,$term),2); echo "<tr><td>Monthly payment:</td><td class='res'> $".$pay."</td></tr>"; echo "<tr><td>Total interest:</td><td> $".(($term*$pay*$period)-$balance)."</td></tr>"; ?> </table> <?php echo "<br/><br/>"; echo "<table class='detail'>"; echo "<tr><td>Year</td><td>Principial</td><td>Interest</td><td>Payment</td></tr>"; for ($i=0;$i<($term*$period);$i++){ $tmp = (($pay) - ($balance*($rate/100/$period))); $diff = round($tmp,2); $int = round(($balance*$rate/100/$period),2); $princ = $balance - $diff; $balance = round($balance,0); echo "<tr><td>$i. month</td><td> $".number_format($balance)."</td><td> $".number_format($int)."</td><td> $".number_format($pay)."</td></tr>"; $balance = $princ; } echo "</table>"; ?> </div> <?php } ?> <div id="source"><a href="http://www.theloanindex.net/" >Mortgage Payment Calculator</a></div> </div> </body>
Verilmiş cavablar və yazılan şərhlər (1 cavab var)
1
8-ci, 53-cu və 61-ci sətrlərə diqqət.
Bir də years sözünü months eləmişəm.
Sual verin
Cavab verin