Advertisement

04.10.2008 at 07:02AM PDT, ID: 23311723
[x]
Attachment Details

c#.NET dealing with dollars in text boxes - converting strings to numbers and back

Asked by jackjohnson44 in C# Programming Language, .NET, Microsoft Visual Basic.Net

I have a form where people enter numbers into text boxes.  When they leave the textbox, I format the number into a dollar ammount, meaning I add a dollar sign.  I have to do calculations on the field and am running into trouble.  I am using the code below.  First I strip the dollar sign, then do a try parse to get the number.  I ran into trouble when loading the form from a db because negative numbers were being shown with parenthases and not a negative sign.

1. How do I get a decimal out of a string in the format ($4000.00) I would also like to be able to have the function I make be able to handle -$4000.

           decimal NetPlannedFee=0;
            if (!((decimal.TryParse(txtFee.Text.Replace("$",""), out NetPlannedFee)) && (txtFee.Text != "")))
                NetPlannedFee = 0;
Start Free Trial
[+][-]04.10.2008 at 07:24AM PDT, ID: 21325105

Assisted solutions are selected by the member who asked the question as a comment that contributed to their question's solution.

Start your 7-day free trial to view this Assisted Solution or ask the Experts your question.

 
[+][-]04.10.2008 at 07:26AM PDT, ID: 21325140

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]04.10.2008 at 07:31AM PDT, ID: 21325187

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]04.10.2008 at 07:36AM PDT, ID: 21325257

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]04.10.2008 at 07:44AM PDT, ID: 21325354

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]04.10.2008 at 08:57AM PDT, ID: 21326211

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: C# Programming Language, .NET, Microsoft Visual Basic.Net
Sign Up Now!
Solution Provided By: jackjohnson44
Participating Experts: 1
Solution Grade: A
 
 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628