您当前的位置: 首页 >  php

知其黑、受其白

暂无认证

  • 0浏览

    0关注

    1250博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

PHP利息计算方法

知其黑、受其白 发布时间:2021-02-09 15:00:40 ,浏览量:0

一次性本息的利息计算
/**
 * 一次性本息的利息计算
 *
 * @param int $money 本金
 * @param float $annualInterestRate 年化收益率
 * @param int $day 天数
 * @return number 利息
 */
function interest_day($money, $annualInterestRate, $day)
{
    $interestRate = $annualInterestRate / 365;
    return $money * $interestRate * $day;
}

/**
 * 一次性本息
 *
 * @param unknown $a
 */
function aaa($cash, $rate, $month)
{
    // 月利率
    $rate = $rate / 12;
    $c = $cash * $rate * $month;
    $res = [ 'total' => $cash + $c,'cash' => $cash,'rate' => $c ];
    return $c;
}
利息计算
/**
 * 利息计算
 *
 * @param int $money
 * @param floal $annualInterestRate
 * @param int $month
 * @param int $type 0 一次性本息 1 等额本金 2等额本息 3每月还息到期还本
 */
function interest_count($money, $annualInterestRate, $month, $type = 0)
{
    // 月利率
    $interestRate = $annualInterestRate / 12;
    $res = array ();
    if ($type == 0) { // 一次性本息
        $interest = $money * $interestRate * $month;
        $res [] = array ('total' => $money + $interest,'money' => $money,'interest' => $interest,'nper' => 1 );
    } elseif ($type == 1) { // 等额本息
                            // 每月月供额=〔贷款本金×月利率×(1+月利率)^还款月数〕÷〔(1+月利率)^还款月数-1〕
        $trate = $interestRate + 1;
        // $P = round ( ($money * $interestRate * pow ( $trate, $month )) / (pow ( $trate, $month ) - 1), 2 );
        // 每月应还本金=贷款本金×月利率×(1+月利率)^(还款月序号-1)÷〔(1+月利率)^还款月数-1〕
        $res = array ();
        for($i = 1; $i  $principal,'interest' => $interest,'nper' => $i,'diminishing' => $principal * $interestRate );
            // 剩余本金
            $money = $money - $principal;
        }
    } elseif ($type == 3) {
        for($i = 1; $i  $money + $interest,'money' => $money,'interest' => $interest,'nper' => $i );
            } else {
                $res [$i] = array ('total' => $interest,'money' => 0,'interest' => $interest,'nper' => $i );
            }
        }
    }
    return $res;
}
等额本息
/**
 * 等额本息
 *
 * @param int $cash 贷款总额
 * @param unknown $rate 年化收益率
 * @param int $month 贷款月数
 */
function bbb($cash, $rate, $month)
{
    $rate = $rate / 12;
    // 每月月供额=〔贷款本金×月利率×(1+月利率)^还款月数〕÷〔(1+月利率)^还款月数-1〕
    $trate = $rate + 1;
    $a = $cash * $rate * pow ( $trate, $month );
    $b = pow ( $trate, $month ) - 1;
    $P = round ( $a / $b, 2 );
    // 每月应还本金=贷款本金×月利率×(1+月利率)^(还款月序号-1)÷〔(1+月利率)^还款月数-1〕
    $res = array ();
    for($i = 1; $i  $a,'rate' => $d ];
    }
    // print_r ( $res );
    return $res;
}
每月还息到期还本
/**
 * 每月还息到期还本
 */
function ddd($cash, $rate, $month)
{
    // 月利率
    $rate = $rate / 12;
    $res = array ();
    for($i = 1; $i  $cash + $c,'cash' => $cash,'rate' => $c ];
        } else {
            $res [$i] = [ 'total' => $c,'cash' => 0,'rate' => $c ];
        }
    }
    return $res;
}

按年付息到期还本
/**
 * 按年付息到期还本
 *
 * @param unknown $cash
 * @param unknown $rate
 * @param unknown $month
 * @return multitype:multitype:number unknown
 */
function eee($cash, $rate, $month)
{
    $res = array ();
    for($i = 1; $i  $cash + $c,'cash' => $cash,'rate' => $c ];
        } else {
            $res [$i] = [ 'total' => $c,'cash' => 0,'rate' => $c ];
        }
    }
    return $res;
}
关注
打赏
1665558895
查看更多评论
立即登录/注册

微信扫码登录

0.0521s