代码如下:
<?php
function amortizationTable($pNum,$periodicPayment,$balance,$monthlyInterest)
{
$paymentInterest=round ($balance*$monthlyInterest,2);
$paymentPrincipal=round ($periodicPayment-$paymentInterest ,2);
$newBalance=round ($balance-$paymentPrincipal,2);
if ($newbalance < $paymentPrincipal){
     $newBalance=0;
}printf("<tr><td>%d</td>",$pNum);
printf("<td>$%S</td>",number_format($newBalance,2));
printf("<td>$%S</td>",number_format($periodicPayment,2));
printf("<td>$%S</td>",number_format($paymentPrincipal,2));
printf("<td>$%S</td></tr>",number_format($paymentInterest,2));
if($newBalance>0){
$pNum++;
amortizationTable($pNum,$periodicPayment,$newBalance,$monthlyInterest);
}else{
return 0;
}
}
$balance=10000.00;
$interestRate=.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);
$periodicPayment=round($periodicPayment,2);
echo"<table width='50%' align='center' border'1'>";
echo"<tr>
<th>Payment Number </th><th>Balance</th>
<th>Payment</th><th>Principal</th><th>Interest</th>
</tr>";
aomrtizationTable($paymentNumber,$periodicPayment,$balance,$monthlyInterest);
echo"</table>";
?>
为什么显示的结果是下面的:Fatal error: Call to undefined function aomrtizationTable() in C:\AppServ\www\test.php on line 38
Payment Number  Balance Payment Principal Interest 

解决方案 »

  1.   

    aomrtizationTable($paymentNumber,$periodicPayment,$balance,$monthlyInterest);
    amo ... 不是 aom
      

  2.   

    先谢谢你了,我改过了,可是结果怎么是:
    Payment Number  Balance Payment Principal Interest 
    1        $      $       $       $ 
      

  3.   

    注意大小写!
    function amortizationTable($pNum,$periodicPayment,$balance,$monthlyInterest) {
      $paymentInterest=round ($balance*$monthlyInterest,2);
      $paymentPrincipal=round ($periodicPayment-$paymentInterest ,2);
      $newBalance=round ($balance-$paymentPrincipal,2);
      if ($newBalance < $paymentPrincipal){
        $newBalance=0;
      }  printf("<tr><td>%d</td>",$pNum);
      printf("<td>$%s</td>",number_format($newBalance,2));
      printf("<td>$%s</td>",number_format($periodicPayment,2));
      printf("<td>$%s</td>",number_format($paymentPrincipal,2));
      printf("<td>$%s</td></tr>",number_format($paymentInterest,2));
      if($newBalance>0){
        $pNum++;
        amortizationTable($pNum,$periodicPayment,$newBalance,$monthlyInterest);
      }else{
        return 0;
      }
    }
      

  4.   

    Payment Number  Balance Payment Principal Interest 
    1 $ $ $ $ 
    2 $ $ $ $ 
    3 $ $ $ $ 
    4 $ $ $ $ 
    5 $ $ $ $ 
    6 $ $ $ $ 
    7 $ $ $ $ 
    8 $ $ $ $ 
    9 $ $ $ $ 
    10 $ $ $ $ 
    11 $ $ $ $ 
    12 $ $ $ $ 
    13 $ $ $ $ 
    14 $ $ $ $ 
    15 $ $ $ $ 
    16 $ $ $ $ 
    17 $ $ $ $ 
    18 $ $ $ $ 
    19 $ $ $ $ 
    20 $ $ $ $ 
    21 $ $ $ $ 
    22 $ $ $ $ 
    23 $ $ $ $ 
    24 $ $ $ $ 
    25 $ $ $ $ 
    26 $ $ $ $ 
    27 $ $ $ $ 
    28 $ $ $ $ 
    29 $ $ $ $ 
    30 $ $ $ $ 
    31 $ $ $ $ 
    32 $ $ $ $ 
    33 $ $ $ $ 
    34 $ $ $ $ 
    35 $ $ $ $ 
    36 $ $ $ $ 
    37 $ $ $ $ 
    38 $ $ $ $ 
    39 $ $ $ $ 
    40 $ $ $ $ 
    41 $ $ $ $ 
    42 $ $ $ $ 
    43 $ $ $ $ 
    44 $ $ $ $ 
    45 $ $ $ $ 
    46 $ $ $ $ 
    47 $ $ $ $ 
    48 $ $ $ $ 
    49 $ $ $ $ 
    50 $ $ $ $ 
    51 $ $ $ $ 
    52 $ $ $ $ 
    53 $ $ $ $ 
    54 $ $ $ $ 
    55 $ $ $ $ 
    56 $ $ $ $ 
    57 $ $ $ $ 
    58 $ $ $ $ 
    59 $ $ $ $ 
    60 $ $ $ $ 
    为什么出现这样的结果?
      

  5.   

    Payment Number  Balance Payment Principal Interest 
    1 $9,855.75 $192.17 $144.25 $47.92 
    2 $9,710.81 $192.17 $144.94 $47.23 
    3 $9,565.17 $192.17 $145.64 $46.53 
    4 $9,418.83 $192.17 $146.34 $45.83 
    5 $9,271.79 $192.17 $147.04 $45.13 
    6 $9,124.05 $192.17 $147.74 $44.43 
    7 $8,975.60 $192.17 $148.45 $43.72 
    8 $8,826.44 $192.17 $149.16 $43.01 
    9 $8,676.56 $192.17 $149.88 $42.29 
    10 $8,525.97 $192.17 $150.59 $41.58 
    11 $8,374.65 $192.17 $151.32 $40.85 
    12 $8,222.61 $192.17 $152.04 $40.13 
    13 $8,069.84 $192.17 $152.77 $39.40 
    14 $7,916.34 $192.17 $153.50 $38.67 
    15 $7,762.10 $192.17 $154.24 $37.93 
    16 $7,607.12 $192.17 $154.98 $37.19 
    17 $7,451.40 $192.17 $155.72 $36.45 
    18 $7,294.93 $192.17 $156.47 $35.70 
    19 $7,137.71 $192.17 $157.22 $34.95 
    20 $6,979.74 $192.17 $157.97 $34.20 
    21 $6,821.01 $192.17 $158.73 $33.44 
    22 $6,661.52 $192.17 $159.49 $32.68 
    23 $6,501.27 $192.17 $160.25 $31.92 
    24 $6,340.25 $192.17 $161.02 $31.15 
    25 $6,178.46 $192.17 $161.79 $30.38 
    26 $6,015.90 $192.17 $162.56 $29.61 
    27 $5,852.56 $192.17 $163.34 $28.83 
    28 $5,688.43 $192.17 $164.13 $28.04 
    29 $5,523.52 $192.17 $164.91 $27.26 
    30 $5,357.82 $192.17 $165.70 $26.47 
    31 $5,191.32 $192.17 $166.50 $25.67 
    32 $5,024.03 $192.17 $167.29 $24.88 
    33 $4,855.93 $192.17 $168.10 $24.07 
    34 $4,687.03 $192.17 $168.90 $23.27 
    35 $4,517.32 $192.17 $169.71 $22.46 
    36 $4,346.80 $192.17 $170.52 $21.65 
    37 $4,175.46 $192.17 $171.34 $20.83 
    38 $4,003.30 $192.17 $172.16 $20.01 
    39 $3,830.31 $192.17 $172.99 $19.18 
    40 $3,656.49 $192.17 $173.82 $18.35 
    41 $3,481.84 $192.17 $174.65 $17.52 
    42 $3,306.35 $192.17 $175.49 $16.68 
    43 $3,130.02 $192.17 $176.33 $15.84 
    44 $2,952.85 $192.17 $177.17 $15.00 
    45 $2,774.83 $192.17 $178.02 $14.15 
    46 $2,595.96 $192.17 $178.87 $13.30 
    47 $2,416.23 $192.17 $179.73 $12.44 
    48 $2,235.64 $192.17 $180.59 $11.58 
    49 $2,054.18 $192.17 $181.46 $10.71 
    50 $1,871.85 $192.17 $182.33 $9.84 
    51 $1,688.65 $192.17 $183.20 $8.97 
    52 $1,504.57 $192.17 $184.08 $8.09 
    53 $1,319.61 $192.17 $184.96 $7.21 
    54 $1,133.76 $192.17 $185.85 $6.32 
    55 $947.02 $192.17 $186.74 $5.43 
    56 $759.39 $192.17 $187.63 $4.54 
    57 $570.86 $192.17 $188.53 $3.64 
    58 $381.43 $192.17 $189.43 $2.74 
    59 $191.09 $192.17 $190.34 $1.83 
    60 $0.00 $192.17 $191.25 $0.92 #3 修改后的函数,没有问题