Handling user input - Float, and globalisation

  • Thread starter Thread starter Cralis
  • Start date Start date
C

Cralis

Hi guys,

I have a winforms scree, which allows a user to enter a decimal GPS
position, such as -27.34212

Problem is, in Romainia, they would enter -27,34212, and in the US, it
would be -27.34212

So what I am doing is handling all float with the Invarient type, and
they all get treated as US style. However, when thre's user input ...
how should I handle this?

At the moment, I take the EditBox.Text and di a string.replace on the
',', and replace with a '.', but that seems very dodgy. Is there a
better way for this?
 
I have a winforms scree, which allows a user to enter a decimal GPS
position, such as -27.34212

Problem is, in Romainia, they would enter -27,34212, and in the US, it
would be -27.34212

So what I am doing is handling all float with the Invarient type, and
they all get treated as US style. However, when thre's user input ...
how should I handle this?

At the moment, I take the EditBox.Text and di a string.replace on the
',', and replace with a '.', but that seems very dodgy. Is there a
better way for this?

If you explain on the screen that they have to use decimal period
and you check the input with regex and give them an error
message if the input is not valid, then I think you have
done what you can do.

Arne
 
Thanks Pete.

Problem is, I am exporting to a google KML file, which expects the US
format (point, as opposed to comma, in float type numbers).

I've gone with the string.replace, which seems hackey, but it's
working 100% so far. I then do some TryParse stuff to ensure it's all
worked out before accepting the numbers as floats.
 
Back
Top