total_paid (currency units): Sum of all payments over the loan
total_interest (currency units): Total interest paid over the loan
Steps
Convert the annual rate to a decimal: r = annual_rate_percent / 100; monthly rate i = r / 12.
Compute the fixed monthly payment using the standard annuity formula: payment = principal * i * (1+i)^months / ((1+i)^months - 1) (or principal/months if i = 0).
total_paid = payment * months.
total_interest = total_paid - principal.
Round monthly_payment, total_paid, and total_interest to 2 decimals (money to cents).
Constants
None.
Sources
Principles of Corporate Finance (McGraw-Hill, 2026-09-30T19:31:29Z) - Total interest equals the sum of all fixed payments minus the original principal