如何对十进制数执行 Integer.parseInt()?
Java代码如下:
String s = "0.01";
int i = Integer.parseInt(s);
但是这会引发 NumberFormatException... 可能出了什么问题?
However this is throwing a NumberFormatException... What could be going wrong?
推荐答案
0.01 不是整数(整数),所以你当然不能把它解析为一.请改用 Double.parseDouble
或 Float.parseFloat
.
0.01 is not an integer (whole number), so you of course can't parse it as one. Use Double.parseDouble
or Float.parseFloat
instead.
相关文章