473,503 Members | 1,805 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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(items[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(items[2])
'double.Parse(items[2])' threw an exception of type 'System.FormatException'
base {System.SystemException}: {"Input string was not in a correct
format."}

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

Thanks in advance!

Mika
Oct 9 '08 #1
2 3804
Mika M wrote:
?items[2]
"6215.1058"
?double.Parse(items[2])
'double.Parse(items[2])' threw an exception of type
'System.FormatException'
base {System.SystemException}: {"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(items[2], CultureInfo.InvariantCulture)

--
Göran Andersson
_____
http://www.guffa.com
Oct 9 '08 #2
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.FormatException'
base {System.SystemException}: {"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(items[2], CultureInfo.InvariantCulture)
Oct 9 '08 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
5018
by: moondaddy | last post by:
I'm writing an app in vb.net 1.1 and I need to parse strings that look similar to the one below. All 5 rows will make up one string. I have a form where a use can copy/paste data like what you...
9
14072
by: Python.LeoJay | last post by:
Dear all, i need to parse billions of numbers from a file into float numbers for further calculation. i'm not satisfied with the speed of atof() function on my machine(i'm using visual c++ 6)....
2
3487
by: rajarshi.guha | last post by:
Hi, recently having discovered ElementTree I'm stumped by a very simple problem, which I can't find the answer to. I have some XML in a string object. Now the parse() method of ElementTree takes...
3
5181
by: SharpCoderMP | last post by:
i've run into some trouble using data from xml inside my app. the scenario is simple. input data looks more or less like this: <item> <name>MyName</name> <somefloat>11.5</somefloat> </item> ...
6
8537
by: trevor | last post by:
Incorrect values when using float.Parse(string) I have discovered a problem with float.Parse(string) not getting values exactly correct in some circumstances(CSV file source) but in very similar...
1
1428
by: sachin | last post by:
hi everyone ....... could u please help me out of this........... i have a string with value........ dim str as string="789456123078945612307894561230" now i need to take the modulos of...
2
2099
by: Nicolai.Schoenberg | last post by:
When i try it like you say, he ignores the dot. For example s = "12.45"; d = double.Parse(s); d will be 1245.0 :( pls help
11
3493
by: Peter Pei | last post by:
One bad design about elementtree is that it has different ways parsing a string and a file, even worse they return different objects: 1) When you parse a file, you can simply call parse, which...
2
2820
by: hsachdevah | last post by:
Hi, I developed an application for my study project to do some mathematical calculations. In this application, I am reading from a text file which contains some numbers. Now the problem is...
0
7199
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7074
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7322
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7451
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5572
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5000
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4667
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
1
731
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
374
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.