C# 抵押计算器:计算每月付款总额的公式

C# 抵押计算器:计算每月付款总额的公式,c#,C#,如果我们通过给定的公式,在利率和贷款金额的固定变量下获得月度付款,那么如果给出月度付款,如何获得年内的月度付款总额 // r is the percentage rate per period divided by 100 // n is numbers of years * 12 / number of payments // Principal amount = House value * ( 90 / 100 ) // payment = ((Principal amoun

如果我们通过给定的公式,在利率和贷款金额的固定变量下获得月度付款,那么如果给出月度付款,如何获得年内的月度付款总额

//   r is the percentage rate per period divided by 100
//   n is numbers of years * 12 / number of payments
//   Principal amount = House value * ( 90 / 100 )
//   payment = ((Principal amount *  (1 + r/12) ^ n) * r) / (12 * ((1 + r/12)^n - 1)));

double loanAmount = (double)txtLoanAmount.CurrentValue * ((double)txtFinancing.CurrentValue / 100); // house value * % Financing
double interestRate = (double)udInterest.Value / 100;  // calculate interest from 100%
double termOfLoan = (double)(udTerm.Value * 12); // monthly term
double payment;

payment = (loanAmount) * (Math.Pow((1 + interestRate / 12), termOfLoan) * interestRate) / (12 * (Math.Pow((1 + interestRate / 12), termOfLoan) - 1));
                txtPayment.Text = payment.ToString("N2");

您需要Excel中的
nper
函数的等效项。您要寻找的方程式是:

N=(-log(1-i*a/p))/log(1+i)

a = amount    
i = interest rate (divide by 12 if yearly rate)
p = payment amount