Specify double.TryParse(..) number format?
I get lat/lon strings from an API back in the format e.g. '37.766713' or '-122.428938' (see http://en.wikipedia.org/wiki/Decimal_degrees) and want to parse these into a double each, however, double.TryParse(string, out doubleInstance) gives me a double of '37766713,0'. Is there any elegant way to specify the input format for the parsing? Doing string.Repl开发者_如何学运维ace(".", ",") hurts a little bit.
This is a culture issue. Try using the InvariantCulture
.
double d = Double.Parse("37.766713", CultureInfo.InvariantCulture);
Sigh.. should have looked a little longer.. this does the trick: Double.TryParse() input decimal separator different than system decimal separator
Take a look of the Convert.ToDouble() or Double.parse(), you can specify a IFormartProvider for the specific number format.
精彩评论