Click here to Skip to main content
16,018,264 members
Articles / Desktop Programming / MFC
Article

Financial Calculations in C#

Rate me:
Please Sign up or sign in to vote.
1.27/5 (8 votes)
14 Jan 20022 min read 86.6K   2K   16   4
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


Written By
Web Developer
United States United States
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#.

Comments and Discussions

 
GeneralMy vote of 1 Pin
gorv628-Jan-09 17:22
gorv628-Jan-09 17:22 
GeneralMy vote of 1 Pin
KiwiPiet17-Dec-08 14:55
KiwiPiet17-Dec-08 14:55 
Generalwindows calculator in c# Pin
seeng22-Jun-07 14:51
seeng22-Jun-07 14:51 
GeneralRe: windows calculator in c# Pin
je_gonzalez18-Mar-09 12:40
je_gonzalez18-Mar-09 12:40 
See http://www.codeproject.com/KB/recipes/eval3.aspx

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

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