开发者

Very weird problem with Convert.Double in ASP.NET

I have a very simple code that works on my PC:

    String latitude = "2.3444";
    String longitude = "34.333";

    Double lat = Convert.ToDouble(latitude);
    Double lng = Convert.ToDouble(longitude);

In my pc "." is decimal separator.

I uploaded to server. It fails. I looked at Regional Settings, it was "," as decimal separator. I changed it to ".". I stopped my web app and resta开发者_如何转开发rted it but it still fails. Why ?


Try adding CultureInfo.InvariantCulture.

using System.Globalization

String latitude = "2.3444";
String longitude = "34.333";

Double lat = Convert.ToDouble(latitude, CultureInfo.InvariantCulture);
Double lng = Convert.ToDouble(longitude, CultureInfo.InvariantCulture);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜