note 50833 deleted from ref.math by cmb
| From: | cmb@php.net | Date: | Sun, 21 Jul 2019 08:59:51 +0000 |
| Subject: | note 50833 deleted from ref.math by cmb | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-211661@lists.php.net to get a copy of this message | ||
Note Submitter: eric at woolhiser dot com
----
For all you guys writing mortgage calculators out there:
<?php
function payment($apr,$n,$pv,$fv=0.0,$prec=2){
/* Calculates the monthly payment rouned to the nearest penny
** $apr = the annual percentage rate of the loan.
** $n = number of monthly payments (360 for a 30year loan)
** $pv = present value or principal of the loan
** $fv = future value of the loan
** $prec = the precision you wish rounded to
*/
/****************************************\
** No Warranty is expressed or implied. **
*****************************************/
if ($apr !=0) {
$alpha = 1/(1+$apr/12);
$retval = round($pv * (1 - $alpha) / $alpha /
(1 - pow($alpha,$n)),$prec) ;
} else {
$retval = round($pv / $n, $prec);
}
return($retval);
}
?>