Solved

Convert textbox value(string)  to decimal

Posted on 2007-11-30
2
4,935 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
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…
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…
Both in life and business – not all partnerships are created equal. As the demand for cloud services increases, so do the number of self-proclaimed cloud partners. Asking the right questions up front in the partnership, will enable both parties …

910 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

21 Experts available now in Live!

Get 1:1 Help Now