Skip to content

Instantly share code, notes, and snippets.

@guandaxia
Created November 8, 2018 13:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save guandaxia/8ae19a9d984ca3ba2f9aa0daf8163648 to your computer and use it in GitHub Desktop.
Save guandaxia/8ae19a9d984ca3ba2f9aa0daf8163648 to your computer and use it in GitHub Desktop.
贷款计算
<?php
//每月月供额=(贷款本金÷还款月数)+(贷款本金-已归还本金累计额)×月利率
$totalMoney = 770000;
$monthCount = 360;
$yuehuankuan= $totalMoney/$monthCount;
$yuehuankuanTotal = 0;
$lixi = 0; //每个月利息
$lixiTotal = 0; //总利息
$daer = 0; //大额还款
$yihuan = 0; //已还款金额
for ($i=0; $i < $monthCount; $i++) {
$daer = 0;
if($i!=0 && $i%11 == 0){
echo "还大额…………\n";
$daer = 20000;
}
$lixi = ($totalMoney - $yuehuankuan*$i - $daer)* (0.049/12);
if($lixi < 0){
$lixi = 0;
}
$huan = $yuehuankuan + $lixi;
$yihuan += $huan + $daer;
$lixiTotal += $lixi;
echo "第".($i+1)."个月, 还款:".round($huan, 2)."元, 利息:".round($lixi, 2)." 总还款:".round($yihuan, 2)."元,剩余未还:".round(($totalMoney - $yihuan + $lixiTotal),2)."元\n";
if(($totalMoney - $yihuan + $lixiTotal) < $yuehuankuan){
break;
}
}
echo "共还款:".round($yihuan, 2)."\n";
echo "总利息:".round($lixiTotal, 2)."\n";
//30年 56.75
//25年 47.31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment