日期:2014-05-19  浏览次数:20798 次

如何把字符“23.00”转成int型!急!
如何把字符“23.00”转成int型!
convert,parse,都抱错!
“Input   string   was   not   in   a   correct   format.”

------解决方案--------------------
(int)decimal.Parse(23.00);
------解决方案--------------------
string str = "23.00 ";
int a = (int)double.Parse(str);
------解决方案--------------------
string str = "23.00 ";
int i = (int)Convert.ToSingle(str);
------解决方案--------------------
string s = "23.00 ".Substring(0,IndexOf( '. '));
int i = int.Parse(s);
------解决方案--------------------
string s = "23.00 ";
s = s.Substring(0,s.IndexOf( '. '));
int i = int.Parse(s);
------解决方案--------------------
如果需要考虑四舍五入可以先转成double
string s= "23.00 ";
double dTemp=double.Parse(s);
int iTemp=Convert.ToInt32(dTemp);
如果不需要,就可以用
string s = "23.00 ";
s = s.Substring(0,s.IndexOf( '. '));
int i = int.Parse(s);