Click here to Skip to main content
Licence 
First Posted 14 Jan 2002
Views 56,977
Bookmarked 15 times

Financial Calculations in C#

By | 14 Jan 2002 | Article
C# Windows Application to calculate monthly loan payment
Here is a C# Application I developed for calculating the monthly payment for a loan, given the loan amount, interest rate and the loan period.

Sample Image - PMTApp.gif

I have used four labels, four text boxes and two buttons on a simple Windows form as shown in the screenshot. In addition, a status bar along the bottom of the form is used to describe what is expected in each text field.

Introduction

The monthly payment needed to amortize a loan for a given interest rate and loan period can be calculated fairly easily using a financial calculator such as HP-12C or referring to tables in a Financial Accounting book. This small C# application uses the standard formulas to calculate the monthly payments quickly and easily. The user enters the present value of the loan amount in the first text box, followed by the annual interest rate and the number of payments for the loan. The Calculate button computes the monthly payment and displays the result in the fourth text box. Clicking the Exit button quits the application. Tool tips are also displayed when the mouse hovers over each text box. A timer control is used to display the right message in the status bar. The text boxes prevent non-numeric entry, by filtering out characters other than 0-9 and the decimal point. The user is not allowed to edit the fourth text box (Payment). See the event handler under the textBox1.KeyPress for details of how non-numeric keys are handled. The KeyPressEventHandler takes care of this. The calculation for monthly payments is performed by the static method calcPayment that is invoked by the click event of the Calculate button. The use of both the status bar and tooltips may appear to be an overkill. However, I left them both in simply to illustrate the use of the tooltips and the status bar messages for helping the user with data input. Comments are welcome.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

About the Author

Shashi Menon

Web Developer

United States United States

Member

I am a graduate engineer with over 20 years experience in engineering and computer programming. I have programmed in Fortran, Basic, TurboPascal,C, C++, Visual Basic, Java and now C#. I have developed and co-developed several commercial apps that are currently marketed for engineers in the Oil and Gas industry. I have been working with .NET and C# since the Beta 1 version. I am currently developing an online course and a 2 day Workshop in C#.


Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
GeneralMy vote of 1 Pinmembergorv6217:22 8 Jan '09  
GeneralMy vote of 1 Pinmembermwdiablo14:55 17 Dec '08  
Generalwindows calculator in c# Pinmemberseeng14:51 22 Jun '07  
GeneralRe: windows calculator in c# Pinmemberje_gonzalez12:40 18 Mar '09  

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.

Permalink | Advertise | Privacy | Mobile
Web04 | 2.5.120517.1 | Last Updated 15 Jan 2002
Article Copyright 2002 by Shashi Menon
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid