Click here to Skip to main content
14,700,041 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:

I am trying to calculate the Amortization Schedule. The monthly Payments are being calculated in a separate method monthlyPayments() . I compared it with a Amortization Schedule calculator online and the problem is while the principle balance(newPrincipleBalance), monthlyInterest , EMI(monthly payments) are being calculated correctly , the monthlyPrincipal is not. It keeps decreasing instead of increasing. What can I do to correct it?

            double principal = 10000;
            double rate =0;
            double EMI;
            double monthlyInterest;
            double monthlyPrincipal;
            double newPrincipalBalance;

            for (int i = 0; i <= 24; i++)

                Console.WriteLine("principal " + principal);
                EMI = Math.Round(monthlyPayments(principal, 5, 2));
                Console.WriteLine("EMI " + EMI);

                monthlyInterest = (principal * rate) / 12;
                monthlyInterest = Math.Round((principal * 5 / 100) / 12);
                Console.WriteLine("monthlyInterest " + monthlyInterest);

                monthlyPrincipal = Math.Round(EMI - monthlyInterest);
                Console.WriteLine("monthlyPrincipal " + monthlyPrincipal);

                newPrincipalBalance = Math.Round(principal - monthlyPrincipal);
                Console.WriteLine("newPrincipalBalance " + newPrincipalBalance);
                principal = newPrincipalBalance;
     public static double monthlyPayments(double principal, double rate, int years)
            rate = rate / 1200;
            years = years * 12;

            double F = (double)Math.Pow((double)(1 + rate), years);
            return principal * (rate * F) / (F - 1);


What I have tried:

I have compared it with the other codes online, still can't figure out what's wrong.
Updated 26-Sep-20 9:37am
Patrice T 26-Sep-20 13:20pm
Show input, actual output and expected output.

The "monthly principal" would be the difference between the "principal balance" of the current month and that of the previous month. You say the "balances" are correct, then the difference should be correct.

You need to "carry forward" the previous month's balance for your "current month" calculations.

It's referred to as a "declining balance" calculation.
life traveler 26-Sep-20 13:09pm
so how do I calculate the monthlyPrincipal? Wouldn't it be payment(EMI)for the month - Interest? and the balance to carry forward would be principal - monthlyPrincipal?
I found the mistake that I was making. The EMI should be constant throughout the loan period, but I was calculating it within the the loop, which changed it each time with the new principal. Thank you for replying

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900