当前位置: 动力学知识库 > 问答 > 编程问答 >

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 restarted 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);
分享给朋友:
您可能感兴趣的文章:
随机阅读: