

NumberStyles.Float | NumberStyles.AllowThousands got from Reflector Public static bool TryParse(string str, char decimalSep, out double result) String s = GetInvariantParseString(str, decimalSep) It's difficult without specifying what decimal separator to look for, but if you do, this is what I'm using: public static double Parse(string str, char decimalSep)

So even in the fr-CA culture, I need to parse number that will have a point as the decimal separator. I use this function because in French, we use the comma as a decimal separator, but anybody who ever worked in finance will always use the decimal separator on the numpad, but this is a point, not a comma. To my defense, I use this function in a controlled environment where I know that the culture can either be en-US, en-CA or fr-CA. public static double GetDouble(string value, double defaultValue)īeware though, comments are true. I usualy use a multi-culture function to parse user input, mostly because if someone is used to the numpad and is using a culture that use a comma as the decimal separator, that person will use the point of the numpad instead of a comma. !double.TryParse(value,, CultureInfo.InvariantCulture, out result)) !double.TryParse(value,, CultureInfo.GetCultureInfo("en-US"), out result) & If (!double.TryParse(value,, CultureInfo.CurrentCulture, out result) & This is a correct way that Pierre-Alain Vigeant mentioned public static double GetDouble(string value, double defaultValue) I tested both on my computer: double.Parse("3.5", CultureInfo.InvariantCulture) -> 3.5 OKĭouble.Parse("3,5", CultureInfo.InvariantCulture) -> 35 not OK I couldn't write a comment, so I write here:ĭouble.Parse("3.5", CultureInfo.InvariantCulture) is not a good idea, because in Canada we write 3,5 instead of 3.5 and this function gives us 35 as a result. How do I parse a string with a decimal point to a double?
