2017-02-25 150 views
2

我想建立一個汽車金融計算器,我想通過顯示每個月的原則支付提高代碼和每個月的興趣,我有以下代碼汽車金融計算PHP

$interest = 10 /100/12;//10 is the interest rate 
$months = 60; //60 months term 
$loan = 12000;// total loan amount 

$monthly_payment = $loan * $interest/(1-(pow((1+$interest),-$months))); 
$total_payable = $monthly_payment * $months; 
$total_interest = ($total_payable - $loan); 

echo "Monthly Payment = " . $monthly_payment. '<br>'; 
echo "Total Payable = " . $total_payable . '<br>'; 
echo "Total Interest = " . $total_interest . '<br>'; 
echo "Monthly Interest = " . ($total_interest/$months) . '<br>'; 

做什麼我想我需要使用公式此頁面 http://www.ifsautoloans.com/car-loan-interest/

這是公式

$ 100 $ 100 = 10%/ 12個月* $ 12,000)上。因此,第一次付款時,您將支付154.96美元[154.96美元= 254.96美元 - 100美元]。

我只是不明白,謝謝您的幫助

我想要做的是一樣的這個鏈接

http://www.thecalculatorsite.com/finance/calculators/carloancalculator.php

回答

2

我給你快速PHP用形式和輸出表每月視圖沒有任何造型。變量是不言自明的。

<!DOCTYPE html> 
<html> 
    <head> 
    <title>Loan Calculator</title> 
    </head> 
    <body> 
    <div id="form-wrapper"> 
     <h2>Enter your car loan Details...</h2> 
     <form id="calculate-loan" method="post" action=""> 
     <table> 
     <tbody> 
      <tr> 
      <td><label for="currency">Currency:</label></td> 
      <td> 
       <select id="currency" name="currency"> 
        <option>$</option> 
        <option>&#8377;</option> 
       </select> 
      </td> 
      </tr> 
      <tr> 
      <td><label for="vehicle_value">Vehicle Value:</label></td> 
      <td><input type="number" id="vehicle_value" name="vehicle_value"></td> 
      </tr> 
      </tr> 
      <tr> 
      <td><label for="interest_rate">Interest Rate:</label></td> 
      <td><input type="number" min="1" max="100" id="interest_rate" name="interest_rate"></td> 
      </tr> 
      </tr> 
      <tr> 
      <td><label for="months">Months:</label></td> 
      <td><input type="number" step="1" id="months" name="months"></td> 
      </tr> 
      <tr> 
       <td></td> 
       <td><input type="submit" name="submit" value="Submit"></td> 
      </tr> 
     </tbody> 
     </table> 
     </form> 
    </div> 
    <?php 
    if(isset($_POST['submit'])) { 
    ?> 
    <div id="loan-details"> 
    <h2>Vehicle Loan Repayments By Month</h2> 
    <?php 
     $balance = (float) $_POST['vehicle_value']; 
     $monthly_payment = (($_POST['interest_rate'] /(100 * 12)) * $_POST['vehicle_value'])/(1 - pow(1 + $_POST['interest_rate']/1200, (-$_POST['months']))); 
    ?> 
    <p> 
    Loan Payments: <?php echo $_POST['currency'].number_format($monthly_payment * $_POST['months'], 2); ?><br /> 
    Monthly Payment: <?php echo $_POST['currency'].number_format($monthly_payment, 2); ?><br /> 
    Total Interest: <?php echo $_POST['currency'].number_format($monthly_payment * $_POST['months'] - $balance, 2); ?> 
    </p> 
    <table> 
     <tbody> 
      <tr> 
       <th>Month</th> 
       <th>Balance</th> 
       <th>Principal</th> 
       <th>Interest</th> 
       <th>Payment</th> 
      </tr> 
      <?php 
      for($month = 0; $month < (int)$_POST['months']; $month++) { 
       $interest = $balance * $_POST['interest_rate']/1200; 
       $principal = $monthly_payment - $interest; 
      ?> 
       <tr> 
       <td><?php echo $month + 1 ?></td> 
       <td><?php echo $_POST['currency']. number_format($balance, 2) ?></td> 
       <td><?php echo $_POST['currency']. number_format($principal, 2) ?></td> 
       <td><?php echo $_POST['currency']. number_format($interest, 2) ?></td> 
       <td><?php echo $_POST['currency']. number_format($monthly_payment, 2) ?></td> 
       </tr> 
      <?php 
       $balance -= $principal; 
      } 
      ?> 
     </tbody> 
    </table> 
    </div> 
    <?php } ?> 
    </body> 
</html> 
+0

非常感謝你我幾乎在那裏,但你的方式更好,再次感謝 – tuckbloor