我没有得到正确的解决方案。我的问题是php复利。复利是这样的月薪100,利率0.08%,复合频率12每年,时间60个月。
60个月后,资本将为6000,利润将为1322,总计为7322。
public function monthcount($date1){
$begin = new DateTime($date1);
$date2 = date("d M Y");
$end = new DateTime($date2);
$end = $end->modify( ' -1 month ' );
$interval = DateInterval::createFromDateString( ' 1 month ' );
$period = new DatePeriod($begin, $interval, $end);
$counter = 0;
foreach ($period as $dt){
$counter++;
}
return $counter;
}
public function compinterest($p){
$r = 0.08;
$n = 12;
$t = 1/12;
$c = $r/$n;
$p1 = $p*pow(1+$c, $t*$n);
$in1 = $p1-$p;
return $in1;
}
$starting = date( "d M Y", strtotime( "01-04-2013" ));
$getmont = $com->monthcount($starting, $ending);
$p = 6000;
$monthlypay = 100;
$in = 0;
for($i=1; $i<=$getmont; $i++){
$value = $com->compinterest($p);
$in += $value;
$val= $in+$p;
echo $i."Total".$val;
}
答案 0 :(得分:0)
看起来好像你的数学函数可能是问题,我不确定我给出的答案是你想要完成的。要完成代码,我将有助于了解这是否是正确的方向。
$x = .08;
$y = 12;
$z = $x/$y;
$a= ($z+1);
$b=100;
$c=$a*$b;
// $c 1st month plus interest //
$d=($b+$c)*$a;
// $d 2nd month plus interest //
$e=($b+$d)*$a;
echo $c;
echo "\n";
echo $d;
echo "\n";
echo $e;