473,387 Members | 3,781 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

float.Parse(string) xml localization issue

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
knows that my system locale number representation is "xxx,xx" not the
"xxx.xx" (coma instead of dot). well, great, but xml schema float
requires that "dot".

any ideas how to solve this riddle?
Sep 11 '06 #1
3 5168
SharpCoderMP,

Call the overload that takes an IFormatProvider implementation, and then
pass the CultureInfo.InvariantCulture property. That should work.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"SharpCoderMP" <cs*******@interia.pl.NFSPMwrote in message
news:uL**************@TK2MSFTNGP06.phx.gbl...
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
knows that my system locale number representation is "xxx,xx" not the
"xxx.xx" (coma instead of dot). well, great, but xml schema float
requires that "dot".

any ideas how to solve this riddle?

Sep 11 '06 #2
Try:
float.Parse("11.5",
System.Globalization.CultureInfo.InvariantCulture. NumberFormat);

HTH

Ciaran O'Donnell

"SharpCoderMP" wrote:
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
knows that my system locale number representation is "xxx,xx" not the
"xxx.xx" (coma instead of dot). well, great, but xml schema float
requires that "dot".

any ideas how to solve this riddle?
Sep 11 '06 #3
Use the overload that takes an IFormatProvider and pass in
System.Globalization.NumberFormatInfo.InvariantInf o. (And if you need to
handle dates use System.Globalization.DateTimeFormat.InvariantInfo)

/claes

"SharpCoderMP" <cs*******@interia.pl.NFSPMwrote in message
news:uL**************@TK2MSFTNGP06.phx.gbl...
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
knows that my system locale number representation is "xxx,xx" not the
"xxx.xx" (coma instead of dot). well, great, but xml schema float
requires that "dot".

any ideas how to solve this riddle?

Sep 11 '06 #4

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

Similar topics

2
by: j vickroy | last post by:
Howdy, I do not understand the following behavior for: PythonWin 2.3.2 (#49, Oct 2 2003, 20:02:00) on win32. >>> >>> float('0.0') 0.0 >>> row = ('0.0', '1.0', None)
8
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...
2
by: krsgoss | last post by:
I'm trying to do a two column "form" layout based on article here: http://www.alistapart.com/stories/practicalcss/ The idea is to have a label, and a value using definition list markup. I...
6
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...
11
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...
4
by: =?Utf-8?B?ZGF2ZWJ5dGhlc2Vh?= | last post by:
Hi folks, Boolean.Parse("true") returns true, but what if you need to parse something such as - Boolean.Parse("(false && false) || (false || (true && true))"); Does something exist in the...
27
by: GloStix | last post by:
WARNING VIDEO TAKES A WHILE TO LOAD http://screencast.com/t/BWQ6DNtsM I really don't know how to fix this other than putting another div. But I dont' exactly want to do that for every page....
2
by: Mika M | last post by:
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); // items = "6215.1058"...
2
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
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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
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,...
0
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...

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.