Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?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);
Add Comment
Please, Sign In to add comment