Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 267
  • Last Modified:

If a value is non numeric?

If Price is nonnumeric then
   Price = 0.00;

double Price;

How do I check for non numeric.
0
mathieu_cupryk
Asked:
mathieu_cupryk
1 Solution
 
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
 
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
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

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

 
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_jimbelCommented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now