<?php
/**
* Created by PhpStorm.
* User: Administrator
* Date: 2019/1/7 0007
* Time: 19:43
*/
/**
* 等额本息还款-每月还款金额
* @param int $money
* @param float $year_rate
* @param int $month_term
* @return float
*/
function equ_repay_interest_month($money = 0,$year_rate = 0.00,$year_term = 0){
//月利率
$month_rate = round($year_rate / 12,6);
//月期限
$month_term = $year_term * 12;
$item = pow((1 + $month_rate),$month_term);
$return = round($money * $month_rate * $item/($item - 1),4);
return $return;
}
/**
* 等额本息还款-总还款额
* @param int $money
* @param float $year_rate
* @param int $year_term
* @return float
*/
function equ_repay_interest_all($money = 0,$year_rate = 0.00,$year_term = 0){
//月期限
$month_term = $year_term * 12;
return round(equ_repay_interest_month($money,$year_rate,$year_term) * $month_term,2);
}
/**
* 等额本金还款-每月还款金额
* @param int $money
* @param float $year_rate
* @param int $year_term
* @return array
*/
function equ_repay_money_month($money = 0,$year_rate = 0.00,$year_term = 0){
//月利率
$month_rate = round($year_rate / 12,6);
//月期限
$month_term = $year_term * 12;
//每月还额固定本金
$every_month_money = round($money/$month_term,2);
$month_interest = [];
for ($i = 0;$i < $month_term;$i++){
$interest = $money * $month_rate;
$month_interest[] = $every_month_money + $interest;
$money = $money - $every_month_money;
}
return $month_interest;
}
/**
* 等额本金还款-总还款额
* @param int $money
* @param float $year_rate
* @param int $year_term
* @return float
*/
function equ_repay_money_all($money = 0,$year_rate = 0.00,$year_term = 0){
return round(array_sum(equ_repay_money_month($money,$year_rate,$year_term)),2);
}
var_dump(equ_repay_interest_all(600000,0.108,3));
echo "<br/>";
var_dump(equ_repay_money_all(600000,0.108,3));
原文作者:------ 沙蒿 ------
关注我吧《程序员的碎碎念》作者,不会ui的前端不是好后端
不忘初心,牢记使命,对于文章内容有疑问的或者想深入交流学习的朋友可以加我QQ:2283743369
网友评论