我需要转换String表数据库的输入整数值在 C# .NET 4 中并尝试了受此启发的代码Link https://stackoverflow.com/questions/2344411/how-to-convert-string-to-integer-in-c-sharp:
int i;
string Entry_Level = Convert.ToInt32("2,45");
i = Convert.ToInt32(Entry_Level);
但我有这个错误:
编译器错误消息:CS0029:无法将类型“int”隐式转换为“string”
EDIT
解决方法:
decimal i;
string Entry_Level = "2,45";
i = Convert.ToDecimal(Entry_Level);
Response.Write(i.ToString());
Response.End();
输出结果是 2,45,非常感谢!
string Entry_Level = Convert.ToInt32("2,45");
应该
string Entry_Level = "2,45";
为什么不这样做呢:
int i = 2,45;
但由于这不是整数,因此您需要内置十进制类型之一:
/* use this when precision matters a lot, for example when this is a unit price or a percentage value that will be multiplied with big numbers */
decimal i = 2.45
/* use this when precision isn't the most important part.
It's still really precise, but you can get in trouble when dealing with really small or really big numbers.
Doubles are fine in most cases.*/
double i = 2.45
See 此线程有关十进制与双精度的更多信息 https://stackoverflow.com/questions/1165761/decimal-vs-double-which-one-should-i-use-and-when.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)