444,168 Members | 2,548 Online
Need help? Post your question and get tips & solutions from a community of 444,168 IT Pros & Developers. It's quick & easy.

# valid number formats ?

 P: n/a Hi, How can I check if a string corresponds to a valid number format ? e.g : 1,000.00 1.000,00 1 000,00 1'000.00 How to check the above are valid number formats ? Regards Nov 21 '05 #1
12 Replies

 P: n/a Dim x as Double If Double.TryParse("1,000.00", Any, CultureInfo.InvariantCulture, x) Then 'it was parsed and x contains the result Else 'it failed End If -- Jonathan Allen "Sam" wrote in message news:11*********************@g44g2000cwa.googlegro ups.com... Hi, How can I check if a string corresponds to a valid number format ? e.g : 1,000.00 1.000,00 1 000,00 1'000.00 How to check the above are valid number formats ? Regards Nov 21 '05 #2

 P: n/a "Sam" schrieb: How can I check if a string corresponds to a valid number format ? e.g : 1,000.00 1.000,00 1 000,00 1'000.00 How to check the above are valid number formats ? The samples you are giving are concreate instances of certain number formats. You can use 'Double.TryParse' to check if the string can be parsed and interpreted as a number. -- M S Herfried K. Wagner M V P V B Nov 21 '05 #3

 P: n/a Hi, Thx for your replies. I've tried Jonathan's code: Dim x As Double If Double.TryParse(row("Formatting").ToString, NumberStyles.Any, CultureInfo.InvariantCulture, x) Then ..... I don't understand why with 1.000,00 it returns false and with 1,000.00 it returns true. Is 1,000.00 a valid format? I would have thought it was..... Nov 21 '05 #4

 P: n/a Sam, I don't understand why with 1.000,00 it returns false and with 1,000.00 it returns true. Is 1,000.00 a valid format? I would have thought it was..... Do you live in France or are you only using a French email address? Cor Nov 21 '05 #5

 P: n/a Cor, Why this question ? I'm French but I live in London. 1,000.00 and 1.000,00 to me are both valid but maybe 1.000,00 isn't valid in the UK ? Sam Nov 21 '05 #6

 P: n/a Sam, Because it is set in a computer, you use either the English language notation of numbers 1,000.00 or as the other European languages 1.000,00. Your computer sees that from the settings. Cor Nov 21 '05 #7

 P: n/a Ok, then I can't rely on TryParse, because someone based in the UK or in the USA could have a machine with European settings, which would prevent him having a english format.... argh :( this is so annoying! Nov 21 '05 #8

 P: n/a Sam, I really am curious how you solve this. When I type this, than what is the value in your opinion. 1,500 This has nothing to do with programming. A man cannot be a woman (at the same time). Cor Nov 21 '05 #9

 P: n/a hehe... I've got a table in my database that has a few fields amongst which, a Number Format (1,000.00 or 1,000 or whatever), and a Decimal character (, or . or whatever) so I know what is the decimal part. 1,500 if my Decimal character is , then it means this number is one and and a half, otherwise it means it is one thousand and five hundred. I know it 's a arse... Nov 21 '05 #10

 P: n/a "Sam" schrieb: 1,000.00 and 1.000,00 to me are both valid but maybe 1.000,00 isn't valid in the UK ? I don't think that 1.000,00 is valid in the UK, but it's valid in Germany and Austria. -- M S Herfried K. Wagner M V P V B Nov 21 '05 #11

 P: n/a No it was a mistake in my sentence. 1.000,00 is not valid in the UK and 1,000.00 is valid. Nov 21 '05 #12

 P: n/a "Sam" schrieb: No it was a mistake in my sentence. 1.000,00 is not valid in the UK and 1,000.00 is valid. ACK. -- M S Herfried K. Wagner M V P V B Nov 21 '05 #13

### This discussion thread is closed

Replies have been disabled for this discussion.