double.Parse(string) problem

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Mika M

    #1

    double.Parse(string) problem

    Hi,

    Just for fun I'm trying to parse my GPS position string using C# 2005.

    When my code is trying to parse latitude string to double value like...

    double.Parse(it ems[2]); // items[2] = "6215.1058"

    ....I'll just get an error. What's wrong with that?

    Immediate Window:

    ?items
    {Dimensions:[15]}
    [0]: "GPGGA"
    [1]: "065026.000 "
    [2]: "6215.1058"
    [3]: "N"
    [4]: "02546.1629 "
    [5]: "E"
    [6]: "1"
    [7]: "05"
    [8]: "2.7"
    [9]: "171.8"
    [10]: "M"
    [11]: "19.7"
    [12]: "M"
    [13]: ""
    [14]: "0000*5E\r\ n"
    ?items[2]
    "6215.1058"
    ?double.Parse(i tems[2])
    'double.Parse(i tems[2])' threw an exception of type 'System.FormatE xception'
    base {System.SystemE xception}: {"Input string was not in a correct
    format."}

    Now you know at least where I am right now :)
    --

    Thanks in advance!

    Mika
  • =?ISO-8859-1?Q?G=F6ran_Andersson?=

    #2
    Re: double.Parse(st ring) problem

    Mika M wrote:
    ?items[2]
    "6215.1058"
    ?double.Parse(i tems[2])
    'double.Parse(i tems[2])' threw an exception of type
    'System.FormatE xception'
    base {System.SystemE xception}: {"Input string was not in a correct
    format."}
    You probably have a culture setting where the period is not the decimal
    separator. Specify the invariant culture when you parse the string:

    double.Parse(it ems[2], CultureInfo.Inv ariantCulture)

    --
    Göran Andersson
    _____
    Göran Anderssons privata hemsida.

    Comment

    • Mika M

      #3
      Re: double.Parse(st ring) problem

      Yes Göran you are right, thank you!

      Hälsningar från Finland :)


      Göran Andersson wrote:
      Mika M wrote:
      >?items[2]
      >"6215.1058"
      >?double.Parse( items[2])
      >'double.Parse( items[2])' threw an exception of type
      >'System.Format Exception'
      > base {System.SystemE xception}: {"Input string was not in a correct
      >format."}
      >
      You probably have a culture setting where the period is not the decimal
      separator. Specify the invariant culture when you parse the string:
      >
      double.Parse(it ems[2], CultureInfo.Inv ariantCulture)
      >

      Comment

      Working...