2017-02-25 5 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>'; 

이 난이 페이지는 포뮬러

$ 100 $ 100 = 10 %/12개월 * $ 12,000)이다 http://www.ifsautoloans.com/car-loan-interest/

에 수식을 사용해야 할. 결과적으로, 첫 번째 지불금으로 원금 $ 154.96 [$ 154.96 = $ 254.96 - $ 100]를 지불하게됩니다.

난 그냥 내가하고 싶은 것은이 링크와 동일한 도움

주셔서 감사합니다, 그것을 이해하지 못하는 내가 당신에게 빠른 PHP를주는거야

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

답변

2

양식을 사용하지 않고 월별보기를위한 양식 및 출력 표. 변수는 자명하다.

<!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