递归在PHP中的应用举例
%d",$pNum);printf ("$%s", number_format ($newBalance,2));printf ("$%s", number_format ($periodicPayment,2));printf ("$%s", number_format ($paymentPrincipal,2));printf ("$%s", number_format ($paymentInterest,2));#if balance not yet zero, recursively call amortizationTable()if ($newBalance>0){ $pNum++; amortizationTable($pNum, $periodicPayment, $newBalance, $monthlyInterest); }else{ return 0; }}$balance = 10000.00; // 贷款余额$interestRate = 0.0575; //贷款利率$monthlyInterest = $interestRate/12; //每月利率$termLength = 5; //贷款期限,单位为年$paymentsPerYear = 12; //每年支付次数$paymentNumber = 1; //付款迭代$totalPayments = $termLength*$paymentsPerYear; //确定付款次数$intCalc = 1 + $interestRate / $paymentsPerYear; //确定分期付款的利息部分$periodicPayment = $balance * pow($intCalc, $totalPayments)*($intCalc -1)/(pow($intCalc,$totalPayments) -1);//每月还款额限制到小数点后两位$periodcPayment = round($periodicPayment,2);//创建表echo "
Payment Number | Balance | payment | Principal | Interest |
---|