Guest User

Untitled

a guest
Jun 25th, 2018
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.85 KB | None | 0 0
  1. <?php
  2.  
  3. $principal = 800000; //Amount of loan given
  4. $termInMonths = 10; //The duration of loan in months
  5. $interestRate = 3/100; //Interest rate applied on reducing balance
  6. $monthlyPrincipal = $principal/$termInMonths; //Principal agreed per month
  7. $totalPayable = 0; //Hold total amount to be paid at the end of loan term
  8.  
  9. for( $i = 0; $i < $termInMonths; $i++ ) :
  10.  
  11. $nextMonthPayment = ($i == 0) ? $monthlyPrincipal + ($principal * $interestRate) : $monthlyPrincipal + ($principal - ($monthlyPrincipal * $i ) ) * $interestRate;
  12.  
  13. $monthNumber = ( $i == 0 ) ? 1: $monthNumber + 1;
  14.  
  15. echo '<p><b>Month '.$monthNumber.':</b> '.number_format( $nextMonthPayment ).'</p>';
  16.  
  17. $totalPayable += $nextMonthPayment;
  18.  
  19. endfor;
  20.  
  21. echo '<p><b>Total pay: </b>'.number_format( $totalPayable ).'</p>';
  22.  
  23. echo '<p><b>Interest paid: </b>'.number_format( ($totalPayable - $principal) ).'</p>';
Add Comment
Please, Sign In to add comment