Loan Balance

Loan Balance
Situation: A person initially borrows an amount A and in return agrees to make n repayments per year, each of an amount P. While the person is repaying the loan, interest is accumulating at an annual percentage rate of r, and this interest is compounded n times a year (along with each payment). Therefore, the person must continue paying these installments of amount P until the original amount and any accumulated interest is repayed. This equation gives the amount B that the person still needs to repay after t years.
B = A (1 + r/n)nt - P (1 + r/n)nt - 1
--------------------------------------------------------------------------------
(1 + r/n) - 1

where
B = balance after t years
A = amount borrowed
n = number of payments per year
P = amount paid per payment
r = annual percentage rate (APR)