Olman Sánchez

Generation

generate functionMon, 05 Jun 2023

crear una tabla de amortización

function amortization($amount, $yearlyInterestRate, $termInYears) { $monthlyInterestRate = $yearlyInterestRate / 1200; $numberOfPayments = $termInYears * 12; $monthlyPayment = $amount * ($monthlyInterestRate / (1 - pow(1 + $monthlyInterestRate, -$numberOfPayments))); $balance = $amount; $interest = 0; $principal = 0; $totalInterest = 0; $totalPrincipal = 0; echo "Payment # \tInterest \tPrincipal \tBalance"; for ($i = 1; $i <= $numberOfPayments; $i++) { //calculate interest $interest = $monthlyInterestRate * $balance; //calculate principal $principal = $monthlyPayment - $interest; //deduct principal from remaining balance $balance -= $principal; //update totals $totalInterest += $interest;

Questions about programming?Chat with your personal AI assistant