在 C# 中将字符串转换为 double 时出错
Error at converting string to double in c#
我在将字符串转换为双精度时遇到问题。我正在使用 Double.Parse 方法,但它一直崩溃说有这个 "Entry character chain with incorrect format"。我要转换的字符串是这个:21.00000000
。这个功能不支持吗?如果是这样,为什么不呢?
这是错误行 acc.Latitude = double.Parse(accounts.Lat)
.
此致。
您可以使用 Double.TryParse
inestad 来防止输入错误。此方法 returns true
如果可以解析输入字符串。在这种情况下,out
-参数包含实际的 double
-值:
double value;
if (Double.TryParse(accounts.Lat, out value;))
{
/* do something with the value */
}
其实是地域设置的问题。我已将 .
切换为 ,
,并且有效。感谢您的帮助。
我在将字符串转换为双精度时遇到问题。我正在使用 Double.Parse 方法,但它一直崩溃说有这个 "Entry character chain with incorrect format"。我要转换的字符串是这个:21.00000000
。这个功能不支持吗?如果是这样,为什么不呢?
这是错误行 acc.Latitude = double.Parse(accounts.Lat)
.
此致。
您可以使用 Double.TryParse
inestad 来防止输入错误。此方法 returns true
如果可以解析输入字符串。在这种情况下,out
-参数包含实际的 double
-值:
double value;
if (Double.TryParse(accounts.Lat, out value;))
{
/* do something with the value */
}
其实是地域设置的问题。我已将 .
切换为 ,
,并且有效。感谢您的帮助。