PMT功能支付类型 [英] PMT function Payment Type
问题描述
以下是我计算贷款支付的功能,
和excel一样,我需要添加另一个支付类型的参数。
Below is my function to calculate loan payment, As like in excel I need to add another parameter which is payment type.
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个月,因为付款是在月初。
With Type=0, the interest is computed for 1 month because the payment is assumed to be at the end of the month. For Type=1, the interest is computed for 0 months because the payment is at the beginning of the month.
任何人都可以帮我修改上述功能PaymentType功能。
Can anyone help me to modify the above function with this this PaymentType feature.
http:/ /www.techonthenet.com/excel/formulas/pmt.php
提前致谢
推荐答案
我不确定你需要什么样的PaymentType,但是这里我用的是C#中的PMT功能,它是纯粹的C#PMT功能:
I am not sure what you need the PaymentType for, but here what I use for PMT function in C#, it's pure C# PMT function:
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;
}
用法:
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
这篇关于PMT功能支付类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!