java把含小数点的数字字符串转换为int类型
使用Double强转后再转为int
eg: String num ="1.00";
int abc =Double.valueOf(num).intValue();//转换为Int类型
为什么不能直接使用Integer进行强转,是因为 :
public
static
Integer valueOf(String s)
throws
NumberFormatException
//返回初始化为指定 String 值的新的 Integer 对象。若该 String 不能作为 int 分析,则抛出异常。
字符串 “20.0” 是不能作为 int 类型解析的,所以抛出了异常。