By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
464,369 Members | 1,240 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 464,369 IT Pros & Developers. It's quick & easy.

float.Parse(string) xml localization issue

P: n/a
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
Share this Question
Share on Google+
3 Replies

P: n/a
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

P: n/a
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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.