Convert a string value into an int
This question already has an answer here:
What about:
int i = (int) Double.parseDouble(s);
Of course, "20.00" is not in a valid integer format.
String s = "20.00";
is not valid Integer value that is the reason its throwing NumberFormatException .
Format your number using either Double or Float then using narrow casting cast you number to int but you may loose precision if exists.
ie int I = (int) Double.parseDouble(str);
上一篇: “字符串不能转换为int”
下一篇: 将字符串值转换为int
