Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Convert textbox value(string)  to decimal

Posted on 2007-11-30
2
Medium Priority
?
4,951 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 10

Accepted Solution

by:
digitalZo earned 2000 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

Article by: Ivo
C# And Nullable Types Since 2.0 C# has Nullable(T) Generic Structure. The idea behind is to allow value type objects to have null values just like reference types have. This concerns scenarios where not all data sources have values (like a databa…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Suggested Courses

660 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