简体   繁体   English

Javascript中的Excel PMT功能有点差

[英]Excel PMT function in Javascript result is a little off

I run the following Excel function to calculate weekly re-payments. 我运行以下Excel函数来计算每周还款额。

CELL B4 = 15000
=(PMT(6.5%/12,60,(-B4),(0.2*B4),1))*12/52

Where 6.5% = rate, 60 = number of payments, 0.2*15000 = balloon and *12/52 is for calculating weekly repayments. 其中6.5%=利率,60 =付款次数,0.2 * 15000 =气球,* 12/52用于计算每周还款。

The output of the above is 57.62, however when coding it up in JS I end up with 77.11 as the result. 上面的输出是57.62,但是当用JS编码时,结果是77.11。 After checking through it several times I can't seem to find where I've gone wrong. 经过几次检查后,我似乎找不到错误的地方。

Calculation for PMT is done as follows. PMT的计算如下。

var q = Math.pow(1 + rate_per_period, number_of_payments);
return -(rate_per_period * (future_value + (q * present_value))) / ((-1 + q) * (1 + rate_per_period * (type)));

I've created a fiddle showing my PMT calculations. 我创建了一个小提琴,显示了我的PMT计算。

Also, I am using an almost exact copy of the accepted answer in another question here on SO but mine varies slightly. 另外,我在此处关于SO的另一个问题中使用的是几乎完全相同的可接受答案的副本,但我的说法略有不同。

My mistake! 我的错!

I was doing a negative on the PMT function instead of doing the negative on the PV (present value). 我在PMT函数上做一个负数,而不是在PV(现值)上做负数。

var payment = pmt(interest / 12, 60, -(present), future, beginning);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM