Solved

Convert textbox value(string)  to decimal

Posted on 2007-11-30
2
4,932 Views
Last Modified: 2008-04-14
I need to take string values from 2 textboxes (numbers in decimal form) then convert then to decimal so that calculations can be performed, such as adding them.

example: textbox1.text= "2.75"
               textbox2.text = "3.25"

               textbox3.text = "6" (2.75 + 3.25)

please provide C# code, thanks in advance.
0
Comment
Question by:cbrick04
2 Comments
 
LVL 10

Accepted Solution

by:
digitalZo earned 500 total points
ID: 20387176
Convert.ToDecimal((TextBox1.Text.Trim()))
0
 
LVL 55

Expert Comment

by:Jaime Olivares
ID: 20387188
you can use also the Parse() method:

decimal x = decimal.Parse(textbox1.Text)

but, if you want to validate the contents of the textbox for a valid number, use TryParse() instead:

decimal x;
bool valid = decimal.TryParse(textbox1.Text, out x);

This will avoid an exception, so you don't have to use try/catch.

0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

706 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now