如何使用php计算excel pmt

时间:2015-06-27 11:31:58

标签: php html excel

一直在尝试将excel中使用的pmt函数实现到php中。我有公式,但计算显示不正确。

其6年期利率为30年,最终价值为833333。

正确的答案应该是10,541。

付款在期末到期,因此类型为零,现值为零。

<pre>
    $pv = 0;
    $fv = 833333;
    $i = 0.06/12;
    $n = 360;

    $pmt = (($pv - $fv) * $i )/ (1 - pow((1 + $i), (-$n))); 

    echo $pmt;
</pre>

Using this link as reference for formula

3 个答案:

答案 0 :(得分:10)

我在PHPExcel中使用的公式反映了MS Excel的公式:

$PMT = (-$fv - $pv * pow(1 + $rate, $nper)) /
    (1 + $rate * $type) /
    ((pow(1 + $rate, $nper) - 1) / $rate);

,其中

  • $ rate =利率
  • $ nper =期数
  • $ fv是未来价值
  • $ pv是现值
  • $ type是type

当我使用

时,返回与MS Excel相同的结果
=PMT(6%/12, 360, 0, 833333, 0)

使用时会返回-10540.755358736(与MS Excel相同)的结果

=PMT(0.06,30,0,833333,0)

答案 1 :(得分:4)

更清洁的解决方案如下。

* @param float $apr   Interest rate.
* @param integer $term  Loan length in years. 
* @param float $loan   The loan amount.

function calPMT($apr, $term, $loan)
{
  $term = $term * 12;
  $apr = $apr / 1200;
  $amount = $apr * -$loan * pow((1 + $apr), $term) / (1 - pow((1 + $apr), $term));
  return round($amount);
}

function loanEMI()
{
 echo $this->calPMT(16, 1, 1020000);
}

这将为您提供与MS Excel中一样的精确PMT。

来源: https://drastikbydesign.com/blog-entry/excel-pmt-php-cleaner

答案 2 :(得分:2)

这是另一个我遇到过的人。将来可能对某人有用。

$pv = 0;
$fv = 833333;
$i = 0.06;
$n = 30;
$pmt = ((($pv *( pow((1+$i), $n)  )) + $fv) * $i ) / (1 - ( pow((1+$i), $n) ));
echo $pmt;