php 利息更新,使用PHP中的循环输出用户根据本金和利率获得的逐月利息

取利率除以100(循环外,避免每次计算)。

然后,假设你的任期是几个月,你就可以循环计算条款的数目

:

$principal = $_REQUEST['principal'];

$interestRate = $_REQUEST['interestRate'] / 100;

$term = $_REQUEST['term'];

$month = array('January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September','October', 'November', 'December');

$time = 1 / 12; // Getting the "t" for the formula

for ($i = 0; $i < $term; $i++) { // Run the loop for the number of terms

$total = $principal * $interestRate * $time; // Total is interest formula (P * r * t)

$principal += $total; // Add total to principal to calculate for next month

echo "" . $month[$i] . ": Interest: " . $total . ", Principal: " . $principal . "
"; // Output month, interest earned, and new principal

}

?>

我为一个

10000

,利息

5

,和期限

是:

January: Interest: 41.666666666667, Principal: 10041.666666667

February: Interest: 41.840277777778, Principal: 10083.506944444

March: Interest: 42.014612268519, Principal: 10125.521556713

April: Interest: 42.189673152971, Principal: 10167.711229866

May: Interest: 42.365463457775, Principal: 10210.076693324

您可以设置输出格式。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值