473,651 Members | 2,647 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

double.Parse(st ring) 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
Oct 9 '08 #1
2 3830
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
_____
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.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)
Oct 9 '08 #3

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

Similar topics

8
5025
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 see below from excel, word, notepad, etc.. into a textbox on my form. I need to break each line into 2 numbers which I'll use as parameters for another function. in all cases each line will be separated with a vbNewline and in most cases the 2...
9
14090
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). so i wonder is there any faster way to parse string(char array) into float number.
2
3492
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 a filename or file-like object. So I tried creating a StringIO object from the original string and then giving that to parse(). But that does not seem to work. Any pointers to getting ElementTree to parse from a string would be appreciated (of...
3
5199
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> nothing special as you can see. there is a part of my code that converts <somefloatvalue to float. for that i use float.Parse(string)... and i end up with FrmatException... why? because framework is so smart that it
6
8558
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 circumstances(XML file source) and with exactly the same value it gets it perfectly correct all the time. These are the results I got, XML is always correct, CSV are only incorrect for some of the values (above about 0.01) but always gives the...
1
1438
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 this number...... dim dbl as double = cdbl(str) mod 256
2
2104
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
3520
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 returns a elementtree, on which you can then apply xpath; 2) To parse a string (xml section), you can call XML or fromstring, but both return element instead of elementtree. This alone is bad. To make it worse, you have to create an elementtree from...
2
2835
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 that it works correctly on my system but not on some other systems. When I debugged the application on the system where it was not working I found that the method double.parse(string)
0
8275
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8792
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8694
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8457
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
4143
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4280
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2696
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1905
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1585
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.