note 50833 added to ref.math
| From: | eric at woolhiser dot com | Date: | Fri, 11 Mar 2005 04:41:20 +0000 |
| Subject: | note 50833 added to ref.math | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-86233@lists.php.net to get a copy of this message | ||
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);
}
?>
----
Manual Page -- http://www.php.net/manual/en/ref.math.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+50833
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+50833&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+50833&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+50833&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+50833&report=yes&reason=useless
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+50833&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+50833&report=yes
Search -- http://master.php.net/manage/user-notes.php