无法弄清楚如何正确实施公式以将抵押贷款的每月付款转换为 C#

问题描述 投票:0回答:1
static double CalculateMontlyRepayment(double loanAmount, double annualInterestRate, int loanTermYears)
{
    //convert yearly interest into monthly interest.
    double monthlyInterestRate = annualInterestRate / 12.0;

    //Figure out number of monthly payments.
    int loanTermMonths = loanTermYears * 12;

    //The formula to get the monthly payment amount.
    double monthlyPayment = loanAmount * (monthlyInterestRate * Math.Pow(1 + monthlyInterestRate, loanTermMonths)) /
        (Math.Pow(1 + monthlyInterestRate, loanTermMonths) - 1);

    return monthlyPayment;

}

我可以在一张纸上完成它,但将其翻译成代码是我正在努力解决的问题。甚至尝试使用人工智能,但这只会让情况变得更糟。

c# finance
1个回答
0
投票

利息应该是百分比。您的公式将其表示为十进制值。

将下面的行更改为:

// 将年利率百分比转换为小数,然后转换为月利率。 双倍月利率 = (年利率 / 100) / 12.0;

© www.soinside.com 2019 - 2024. All rights reserved.