valid number formats ?

  • Thread starter Thread starter Sam
  • Start date Start date
S

Sam

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
 
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
 
Sam said:
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.
 
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.....
 
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
 
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
 
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
 
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!
 
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
 
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...
 
Sam said:
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top