473,782 Members | 2,699 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

float.Parse(str ing) 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
<somefloatval ue to float. for that i use float.Parse(str ing)... 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 5209
SharpCoderMP,

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

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

"SharpCoder MP" <cs*******@inte ria.pl.NFSPMwro te in message
news:uL******** ******@TK2MSFTN GP06.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
<somefloatval ue to float. for that i use float.Parse(str ing)... 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.Globaliz ation.CultureIn fo.InvariantCul ture.NumberForm at);

HTH

Ciaran O'Donnell

"SharpCoder MP" 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
<somefloatval ue to float. for that i use float.Parse(str ing)... 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.Globaliz ation.NumberFor matInfo.Invaria ntInfo. (And if you need to
handle dates use System.Globaliz ation.DateTimeF ormat.Invariant Info)

/claes

"SharpCoder MP" <cs*******@inte ria.pl.NFSPMwro te in message
news:uL******** ******@TK2MSFTN GP06.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
<somefloatval ue to float. for that i use float.Parse(str ing)... 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
2012
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
5039
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...
2
2441
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 float the dt left, and the dd right with fixed widths for each. This works fine in both IE and FF until I have a <br> elements within the dd elements. IE does not clear subsequent dt's, and they are not floated beneath the multiline dd element,...
6
8599
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...
11
3544
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...
4
6633
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 .NET framework to Parse this kind of string to one final boolean result?
27
3879
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. random div's everywhere Is there any other way? Also I'm trying to get a scaled thumbnail of the orginal picture WHILE maintaining the size of the css box.. Is that possible? Or do I have to scale it in Photoshop and make a separate image =\
2
3846
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" ....I'll just get an error. What's wrong with that?
2
2856
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
9474
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
10308
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...
1
10076
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
9939
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8964
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7486
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5375
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
5507
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2870
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.