0

I have this code in my android application:

double lat = Double.Parse (latCoordinate);

When device language is english every thing is right, but when I select other languages it is not working.

In some languages it say that char '.' is not valid. An in some others parser the double string bad.for example parse "-95.22222" tp -9.522222 .

How can i fix this issue?

Soner Gönül
  • 97,193
  • 102
  • 206
  • 364
Husein Behboudi Rad
  • 5,434
  • 11
  • 57
  • 115
  • 1
    Ouch, looks like you got smacked in the face by the Locale bug. Look [here](http://stackoverflow.com/questions/721950/double-parse-internationalization-problem) – Shark Jul 11 '13 at 10:38
  • 1
    Maybe answered here: http://stackoverflow.com/questions/7477995/locale-independent-string-to-double – jfs Jul 11 '13 at 10:38
  • @Shark - What is the bug? That link doesn't indicate that there is a bug with using different locales. – Chris Dunaway Jul 11 '13 at 16:15
  • @ChrisDunaway Some people write one thousand like this, some write em like `1,000`, some as `1000` and some as `1.000` or even `one-thousand` and all three have to be identical, programatically. All three are different under different Locales. It's not quite a bug, but it's far from desired behaviour. The link I posted contains a workaround on how to use the `Double.Parse` and get desired behaviour :) – Shark Jul 11 '13 at 16:22
  • @Shark - Your first comment seemed to indicate that there might be a bug in Double.Parse. I see now, that the "bug" you referred to was actually in the user's code. – Chris Dunaway Jul 11 '13 at 16:28
  • @ChrisDunaway I was under the impression (or a bad habit) that this category of bugs are all dubbed "Locale bug". I had no intention of misleading that the bug is in `Double.Parse` :) – Shark Jul 11 '13 at 16:54

1 Answers1

0

You should set cultureInfo to en-us like below:

return d.ToString (new CultureInfo ("en-US"));
Husein Behboudi Rad
  • 5,434
  • 11
  • 57
  • 115