C#计算本金、支付次数、利息

C# Value Computation with Principal, Number of Payment, Interest

我正在创建自动付款计算。但是我不知道它的公式。当点击计算付款按钮时,它会自动计算本金、付款次数和利息,然后在付款时输出。

请看截图

// Example1 Computation
Principal 100000
Number of Payments 9
Interest 2
//Then when the calculate payment is click, execute
Payment 12251.54

// Example2 Computation
Principal 200000
Number of Payments 8
Interest 3.5
//Then when the calculate payment is click, execute
Payment 29095.33

// Example3 Computation
Principal 150000
Number of Payments 12
Interest 1.5
//Then when the calculate payment is click, execute
Payment 13752.00

这是我的字符串

String principal = txt_principal.Text;
String numberofPayments = txt_nop.Text;
String interestRate = txt_irpp.Text;


String payment = txt_payment.Text;

请帮助我。提前致谢!

答案在这里:

https://en.wikipedia.org/wiki/Compound_interest

Excel 可以为您做到这一点:=PMT(0.02,9,100000)

公式如下:

Where:

PV = 100000 (principal)
RATE = 0.02 (interest)
NPER = 9 (payments)

PMT = -RATE * ( PV * Math.Pow(1+RATE,NPER)) / ((Math.Pow(1+RATE,NPER)-1));

因此对于您的代码:

double PV = double .Parse(txt_principal.Text);
double NPER = double .Parse(txt_nop.Text);
double RATE = double.Parse(txt_irpp.Text) / 100;

double PMT = -RATE * ( PV * Math.Pow(1+RATE,NPER)) / ((Math.Pow(1+RATE,NPER)-1));
txt_payment.Text = (-PMT).ToString();