Guest User

Untitled

a guest
Jul 16th, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.75 KB | None | 0 0
  1. <?php
  2.  
  3. /**
  4. * Calculates monthly or total payable amount of the loan.
  5. *
  6. * @param integer $amount Loaned amount, default is 1000
  7. * @param integer $percent Percent in which amount should be calculated, default is 15
  8. * @param integer $months Loan duration in months, default is 12 months (1 year)
  9. * @param boolean $total If positive value is passed function returns total payable amount instead of monthly
  10. * @return float Returns 2 decimal float number
  11. */
  12. function calculate_loan($amount = 1000, $percent = 15, $months = 12, $total = FALSE)
  13. {
  14. $rate = 1 - (1 / pow((1 + $percent / 1200), $months));
  15. $monthly = $amount * (($percent / 12) / 100) / $rate;
  16. $total AND $monthly *= $months;
  17. return round($monthly, 2);
  18. }
  19.  
  20. echo calculate_loan(1000, 15, 12);
Add Comment
Please, Sign In to add comment