Click here to Skip to main content
Click here to Skip to main content

Tagged as

The Loan Calculator App

, 5 Jun 2012
Rate this:
Please Sign up or sign in to vote.
Few days ago I added a new App to my inventory on Windows Phone Marketplace. The Loan Calculator app was just something I needed when I was in a hunt for a car (still am). The thing is I wanted to keep it simple. Just input the numbers and see the total, how much, for how long, you know.. just the F
Few days ago I added a new App to my inventory on Windows Phone Marketplace. The Loan Calculator app was just something I needed when I was in a hunt for a car (still am). The thing is I wanted to keep it simple. Just input the numbers and see the total, how much, for how long, you know.. just the FINAL number. Which is what car dealers will never give upfront, because they always play that 101 psychology thing on you.

So I built this app using the common formula that you can see around in many websites. The idea is pretty simple, just input the data and get the total final price and the monthly installments. As an extra you can also see how the amortization for the loan plays along time.

Check it out, assume we want to calculate the final price for a car that cost 25k, we will put a  10% down payment, 2.5k, with an APR of 3.0%, and with a loan term of 3 years. Just enter the data and hit "Calculate"

Then we just get the summary result with the final cost, see that in total we are paying $26,055.78 for the car. And I don't know you, but that's what I really care. The monthly installments are of $654.33, you can also see that in total you will pay $1,055.78 of interest on the car.

On the details tab we get the amortization for the monthly payments. So you can see how much goes to interest and how much to the principal.

The formula is this one:

The only catch is that the "rate" is our APR divided by 1200, so here is the C# code to get the monthly installments based on the formula above.

 var rate = interest/1200;
 var monthly = rate > 0 ? ((rate + rate / (Math.Pow(1 + rate, months) - 1)) * principal) : principal / months

Now, we have to pay interest every month, and is based on what we still owe, so applying that to the monthly installments we can get the amortization for every month. The C# code is as follows:

 public void MonthlyDetails(double carPrice, double interest, double downPayment, int months, double monthly)
        {
            var endingBalance = carPrice - downPayment;
            var rate = interest/1200.0;
            var count = 1;
            while (count <= months)
            {
                var interestPaid = endingBalance*rate;
                var principlePaid = monthly - interestPaid;
                endingBalance -= principlePaid;
                CreateRow(count, String.Format("{0:C}", interestPaid), String.Format("{0:C}",
                           principlePaid),String.Format("{0:C}", endingBalance), count++);
            }
        }

Where "CreateRow" is a method that add the data do the grid on the screen.

Hope you like it!

License

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

Share

About the Author

Leonardo Paneque
Team Leader
United States United States
Leonardo loves to code with C# and thinks .NET platforms rocks.
He has a Master degree in Computer Sciences and likes to share code and ideas.
Follow on   Twitter

Comments and Discussions

 
QuestionApr rate Division Pinmemberledtech37-Jun-12 11:36 
AnswerRe: Apr rate Division PinmemberLeonardo Paneque7-Jun-12 12:38 
GeneralRe: Apr rate Division Pinmemberledtech37-Jun-12 12:51 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Mobile
Web03 | 2.8.140827.1 | Last Updated 5 Jun 2012
Article Copyright 2012 by Leonardo Paneque
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid