News新闻

业界新闻动态、技术前沿
Who are we?

您的位置:首页      乐道系统FAQ      PHP房贷计算器实例代码,等额本息,等额本金

PHP房贷计算器实例代码,等额本息,等额本金

发布日期:2017-04-01 00:00:00 102

实例如下:

debx(); 
   
  function debx() 
  { 
    $dkm   = 240; //贷款月数,20年就是240个月 
    $dkTotal = 10000; //贷款总额 
    $dknl  = 0.0515; //贷款年利率 
    $emTotal = $dkTotal * $dknl / 12 * pow(1 + $dknl / 12, $dkm) / (pow(1 + $dknl / 12, $dkm) - 1); //每月还款金额 
    $lxTotal = 0; //总利息 
    for ($i = 0; $i < $dkm; $i++) { 
      $lx   = $dkTotal * $dknl / 12;  //每月还款利息 
      $em   = $emTotal - $lx; //每月还款本金 
      echo "第" . ($i + 1) . "期", " 本金:", $em, " 利息:" . $lx, " 总额:" . $emTotal, "<br />"; 
      $dkTotal = $dkTotal - $em; 
      $lxTotal = $lxTotal + $lx; 
    } 
    echo "总利息:" . $lxTotal; 
  } 
   
   
  function debj() 
  { 
    $dkm   = 240; //贷款月数,20年就是240个月 
    $dkTotal = 10000; //贷款总额 
    $dknl  = 0.0515; //贷款年利率 
      
    $em   = $dkTotal / $dkm; //每个月还款本金 
    $lxTotal = 0; //总利息 
    for ($i = 0; $i < $dkm; $i++) { 
      $lx   = $dkTotal * $dknl / 12; //每月还款利息 
      echo "第" . ($i + 1) . "期", " 本金:", $em, " 利息:" . $lx, " 总额:" . ($em + $lx), "<br />"; 
      $dkTotal -= $em; 
      $lxTotal = $lxTotal + $lx; 
    } 
    echo "总利息:" . $lxTotal; 
  } 
   
   
  exit;