469,908 Members | 2,219 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,908 developers. It's quick & easy.

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 4927
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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by j vickroy | last post: by
8 posts views Thread by moondaddy | last post: by
2 posts views Thread by krsgoss | last post: by
4 posts views Thread by =?Utf-8?B?ZGF2ZWJ5dGhlc2Vh?= | last post: by
2 posts views Thread by Mika M | last post: by
1 post views Thread by Waqarahmed | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.