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

Financial Calculations in C#

, 14 Jan 2002
Rate this:
Please Sign up or sign in to vote.
C# Windows Application to calculate monthly loan payment
<!-- Article Starts - DO NOT ADD HTML/BODY START TAGS-->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. <!-- Download Links --> <!-- Article image -->

Sample Image - PMTApp.gif

<!-- Add the rest of your HTML here -->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

Share

About the Author

Shashi Menon
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 Pinmembergorv628-Jan-09 17:22 
GeneralMy vote of 1 Pinmembermwdiablo17-Dec-08 14:55 
Generalwindows calculator in c# Pinmemberseeng22-Jun-07 14:51 
GeneralRe: windows calculator in c# Pinmemberje_gonzalez18-Mar-09 12:40 

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.140814.1 | Last Updated 15 Jan 2002
Article Copyright 2002 by Shashi Menon
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid