php 公式中每月定期存款的复利利率
compound rate interest with regular monthly deposits formular in php
所以我想在 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 * //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 ?
所以我想在 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 * //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 ?