Created
December 8, 2010 10:00
-
-
Save otar/733103 to your computer and use it in GitHub Desktop.
Calculates monthly or total payable amount of the loan
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Calculates monthly or total payable amount of the loan. | |
* | |
* @param integer $amount Loaned amount, default is 1000 | |
* @param integer $percent Percent in which amount should be calculated, default is 15 | |
* @param integer $months Loan duration in months, default is 12 months (1 year) | |
* @param boolean $total If positive value is passed function returns total payable amount instead of monthly | |
* @return float Returns 2 decimal float number | |
*/ | |
function calculate_loan($amount = 1000, $percent = 15, $months = 12, $total = FALSE) | |
{ | |
$rate = 1 - (1 / pow((1 + $percent / 1200), $months)); | |
$monthly = $amount * (($percent / 12) / 100) / $rate; | |
$total AND $monthly *= $months; | |
return round($monthly, 2); | |
} | |
echo calculate_loan(1000, 15, 12); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment