If a value is non numeric?

If Price is nonnumeric then
   Price = 0.00;

double Price;

How do I check for non numeric.
mathieu_cuprykAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Guy Hengel [angelIII / a3]Billing EngineerCommented:
check out the TryParse() function, is available on the numerical data types:
http://blog.redditech.com/professional/difference-between-intparse-and-converttoint32-in-c/
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Joel CoehoornDirector of Information TechnologyCommented:
If price is defined as a double, then price *is* numeric.  No need to check anything.
0
mathieu_cuprykAuthor Commented:
say it has a value of 'a'
0
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

VBRocksCommented:
Here's an example of using the TryParse() method that angellll intended you to see.  If it helps you,
credit angellll.

        Dim price As String = ""   'Non numeric

        Dim dPrice As Double
        Double.TryParse(price, dPrice)

        MsgBox(dPrice.ToString())

       
0
Joel CoehoornDirector of Information TechnologyCommented:
From your original post:
 >      double Price;

If Price is defined like that, it will _never_ have a value of 'a'.   A variable defined as a double cannot hold strings.
0
CartoonHeadCommented:
Unless the value is gathered as a string and is to be assigned to a double... in which case TryParse() would be good.

I think maybe the question is a little too vague.
0
anarki_jimbelSenior DeveloperCommented:
Abour VBRocks example: in VBN it's possible to use IsNumeric function. Really, it is possible to to import Microsoft.VisualBasic namespace in C# and use the function in C# (not really recommended).

Read good discussion and explanation of number of approaches you may use:

http://www.codeproject.com/KB/cs/csharp-isnumeric.aspx
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.