无法将字符串转换为double! [英] Can't convert string to double!
本文介绍了无法将字符串转换为double!的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我得到了:
mscorlib.dll中发生了'System.FormatException'类型未处理的异常
附加信息:输入字符串的格式不正确。
执行简单行:
double v1 = Double.Parse(" 7200.0" ;);
有什么问题?
解决方案
zelyal写道:我得到了:
mscorlib.dll中发生了'System.FormatException'类型的未处理异常
附加信息:输入字符串的格式不正确。
执行简单的行:
double v1 = Double.Parse(" 7200.0");
有什么问题?
几乎可以肯定你使用的是错误的CultureInfo。尝试指定
CultureInfo.InvariantCulture进行解析 - 我怀疑它当前是
,假设。是一个千位分隔符而不是小数点。
Jon
zelyal,
适合我。你确定它是这行代码吗?
-
- Nicholas Paldino [.NET / C#MVP]
- mv*@spam.guard.caspershouse.com
" zelyal" <泽**** @ discussions.microsoft.com>在消息中写道
新闻:5C ********************************** @ microsof t.com ...我得到了:
mscorlib.dll中发生了'System.FormatException'类型的未处理异常
附加信息:输入字符串格式不正确。
执行简单行:
double v1 = Double.Parse(" 7200.0");
有什么问题?
文化,或许?
I got :
An unhandled exception of type ''System.FormatException'' occurred in
mscorlib.dll
Additional information: Input string was not in a correct format.
at execution of simple line:
double v1 = Double.Parse ("7200.0");
What''s wrong?
解决方案
zelyal wrote:I got :
An unhandled exception of type ''System.FormatException'' occurred in
mscorlib.dll
Additional information: Input string was not in a correct format.
at execution of simple line:
double v1 = Double.Parse ("7200.0");
What''s wrong?
Almost certainly you''re using the wrong CultureInfo. Try specifying
CultureInfo.InvariantCulture to parse in - I suspect it''s currently
assuming that "." is a thousands separator rather than a decimal point.
Jon
zelyal,
Works for me. Are you sure it is this line of code?
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com
"zelyal" <ze****@discussions.microsoft.com> wrote in message
news:5C**********************************@microsof t.com...I got :
An unhandled exception of type ''System.FormatException'' occurred in
mscorlib.dll
Additional information: Input string was not in a correct format.
at execution of simple line:
double v1 = Double.Parse ("7200.0");
What''s wrong?
culture, perhaps?
这篇关于无法将字符串转换为double!的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文