Double.Parse - Internationalization problem
Posted
by oz
on Stack Overflow
See other posts from Stack Overflow
or by oz
Published on 2009-04-06T15:22:40Z
Indexed on
2010/05/19
21:30 UTC
Read the original article
Hit count: 299
This is driving me crazy. I have the following string in a ASP.NET 2.0 WebForm Page
string s = "0.009";
Simple enough. Now, if my culture is Spanish - which is "es-ES" - and I try to convert the string to Double, I do the following:
double d = Double.Parse(s, new CultureInfo("es-ES"));
what I'd expect is 0,009. Instead, I get 9. I understand that .NET thinks it is a thousand separator, which in en-US is a comma, but shouldn't it take the culture info I'm passing to the parse method and apply the correct format to the conversion?
If I do
double d = 0.009D;
string formatted = d.ToString(new CultureInfo("es-ES"));
formatted is now 0,009. Anybody?
© Stack Overflow or respective owner