NumberUtils.toInt('3.0',-1);
为什么结果是-1,之后看下NumberUtils的源码
public static int toInt(String str, int defaultValue) {
if(str == null) {
return defaultValue;
}
try {
return Integer.parseInt(str);
} catch (NumberFormatException nfe) {
return defaultValue;
}
}
Integer.parseInt(str)报错 所以返回-1
为什么结果是-1,之后看下NumberUtils的源码
public static int toInt(String str, int defaultValue) {
if(str == null) {
return defaultValue;
}
try {
return Integer.parseInt(str);
} catch (NumberFormatException nfe) {
return defaultValue;
}
}
Integer.parseInt(str)报错 所以返回-1