Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

problem with Double.TryParse when I do not know the culture

so I am using a code like this:

Double.TryParse(Value, NumberStyles.Any,  CultureInfo.InvariantCulture, out result);

and for now the language is on French but some clients may use other languages too, so I am not gonna hard code "fr-FR" in the program...but now if I pass "2,00" which should be number two, it is converting it to number two hundred.

any help on how can I do this correctly? thanks

like image 218
Bohn Avatar asked Feb 11 '11 22:02

Bohn


3 Answers

You can get the current culture for the system using CultureInfo.CurrentCulture. Use this instead of InvariantCulture.

like image 135
Daniel DiPaolo Avatar answered Sep 19 '22 05:09

Daniel DiPaolo


If this is a web application, you can look for the Accept-Language header in the request as a hint for which locale to use for the user.

like image 23
Jacob Avatar answered Sep 20 '22 05:09

Jacob


You can use the CurrentCulture property.

like image 21
Stefan Egli Avatar answered Sep 22 '22 05:09

Stefan Egli