使用Integer.parseInt进行解析时,Integer返回NumberFormatException

时间:2020-07-18 17:38:11

标签: java integer

我正在做一个项目,要求我将String解析为Integer。我以前没有遇到过此问题,但是当我尝试将String解析为Integer时,会收到此消息

Exception in thread "main" java.lang.NumberFormatException: For input string: "385.3100",其中385.3100是所讨论的整数。我什么都没做。

String close = (closing.get("4. close").toString()); int money = Integer.parseInt(close); 是我的代码,其中的结尾是JSONObject。

任何帮助将不胜感激!

1 个答案:

答案 0 :(得分:1)

385.3100 不是整数,而是具有十进制精度的数字。使用:

Double.parseDouble() 要么 Float.parseFloat()