一,直接上代码,先转double,再强转int,看你是选择,舍入,还是直接取整数位
var a1 = "1500.76"; var a2 = Convert.ToDouble(a1); var c = Math.Round(Convert.ToDouble(a1), 0); //var b = Convert.ToInt32(a1); //报错 var b3 = Convert.ToInt32(Convert.ToDouble(a1)); var b4 = (int)Convert.ToDouble(a1);
二,结果如下图