【问题标题】:compound rate interest with regular monthly deposits formular in phpphp中定期每月存款公式的复利利率
【发布时间】:2016-03-09 00:24:58
【问题描述】:

所以我试图在 php 中编写一个复利公式,我有这个但它不起作用,有什么想法吗?

<?php

$p = 0;
$pmt = 200;
$r = 0.06;
$t = 3/12;
$n = 12;

$ans = $pmt * (((1 + $r / $n) ^ $n ($t) - 1) / ($r / $n));

echo $ans;

所以我在沙箱中尝试过,我不断得到函数名必须是字符串 看 https://3v4l.org/rdiJ7

【问题讨论】:

  • 如何“不工作”?
  • 我更新我的问题
  • 试试$ans = $pmt * ((1+( $r / $n)) ^ ($r * $n));

标签: php math calculator


【解决方案1】:

根据这个错误,如果你看看你有什么,你可以通过间隔一些东西来发现错误:

$ans = $pmt *  //All good
(((1 + $r / $n) //An extra bracket to start with that is not closed
 ^ //All good
$n ($t) //No operator here. 
- 1) //All good
/ ($r / $n));

所以改成

$ans = $pmt * ((1 + $r / $n) ^ ($n * $t - 1) / ($r / $n));

您需要一个介于 $n$t 之间的运算符。

更新

所以

P = 0 // start amount
pmt = 200 // monthly deposit
r = 0.06 // Interest amount(6%)
t = 1 // time being 1 year
n = 3/12 // investment after 3 months

ans = 606.02  ?

【讨论】:

  • 谢谢马特,我尝试使用的公式包括每月存款
  • 啊,等一下
  • 感谢马特,已经为此工作了很长时间
  • 看看新答案。
  • @Beep 又更新了,又多了一个括号。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-04-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多