I just ran into something very strange, and was just wondering if I was missing something.
I was trying to parse a string (with thousand separators) into a double, and found the below issue.
CultureInfo ci = CultureInfo.CurrentCulture; // en-ZA
string numberGroupSeparator = CultureInfo.CurrentCulture.NumberFormat.NumberGroupSeparator; //numberGroupSeparator = ,
string numberDecimalSeparator = CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator;//numberDecimalSeparator = .
string strValue = "242,445.24";
double try1;
double try2;
bool btry1 = Double.TryParse(strValue, out try1); //try1 = 242445.24 : btry1 = true
bool btry2 = Double.TryParse(strValue, NumberStyles.Any, null, out try2); //try2 = 0.0 : btry2 = false <- STRANGE
double try3 = Convert.ToDouble(strValue); //try3 = 242445.24
Now the reason why I didnt just want to use Convert.ToDouble
is due to scientific notation which has given me some problems before.
Does anybody know why this might be?
EDIT:
I have update my current culture info.
IFormatProvider
? – RedcoatCurrentCulture
? – BlackingtonThread.Current.CurrentCulture = new CultureInfo("en-us")
. – SkuldAny
Indicates that all styles exceptAllowHexSpecifier
are used. This is a composite number style." – SkuldThread.CurrentThread.CurrentCulture = new CultureInfo("en-ZA");
so that we all talk about the same thing. – PokerCultureInfo.GetCultureInfo("en-ZA").NumberFormat.NumberGroupSeparator;
returns a white space. – Blackington