Solved

Convert textbox value(string)  to decimal

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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone 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

Suggested Solutions

Title # Comments Views Activity
Keyboard 2 41
transaction in asp.net, sql server 6 43
Can I command line build a C# application? 6 41
Problem to Office 1 16
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…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

830 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