Solved

Convert textbox value(string)  to decimal

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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
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…
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…

636 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