PMT功能 支付方式

2024-05-05

下面是我计算贷款付款的函数, 就像在 Excel 中一样,我需要添加另一个参数,即付款类型。

function PMT (ir, np, pv, fv ) {
 /*
 ir - interest rate per month
 np - number of periods (months)
 pv - present value
 fv - future value (residual value)
 type - 0 or 1 need to implement that
 */
 pmt = ( ir * ( pv * Math.pow ( (ir+1), np ) + fv ) ) / ( ( ir + 1 ) * ( Math.pow ( (ir+1), np) -1 ) );
 return pmt;
}

如果 Type=0,则计算 1 个月的利息,因为假定付款在月底进行。对于 Type=1,计算 0 个月的利息,因为付款是在月初。

谁能帮我用此 PaymentType 功能修改上述功能?

http://www.techonthenet.com/excel/formulas/pmt.php http://www.techonthenet.com/excel/formulas/pmt.php


我不确定您需要 PaymentType 的目的是什么,但这里我在 C# 中使用 PMT 函数,它是纯 C# PMT 函数:

public static double PMT(double yearlyInterestRate, int totalNumberOfMonths, double loanAmount)
{
    var rate = (double) yearlyInterestRate / 100 / 12;
    var denominator = Math.Pow((1 + rate), totalNumberOfMonths) - 1;
    return (rate + (rate/denominator)) * loanAmount;
}

Usage:

PMT(7, 360, 120000);
// Result: 798.36
PMT(4.5, 360, 137500.47);
// Result: 696.69
PMT(4.13, 360, 61520);
// Result: 298.33
PMT(6.38, 360, 89200);
// Result: 556.78
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

PMT功能 支付方式 的相关文章

随机推荐