0

I am working on a project that requires me to parse a String into an Integer. I have not had this problem before, but when I try to parse a String to an Integer, I get this message

Exception in thread "main" java.lang.NumberFormatException: For input string: "385.3100", where 385.3100 is the integer in question. Nothing I have done is working.

String close = (closing.get("4. close").toString()); int money = Integer.parseInt(close); Is my code, where closing is a JSONObject.

Any help would be appreciated!

2
  • You have to use Double.parseDouble(). Commented Jul 18, 2020 at 17:39
  • Yeah, that worked. I don't know how I forgot to do that, but I appreciate the timely response! Thank you! Commented Jul 18, 2020 at 17:41

1 Answer 1

1

385.3100 is not an integer but a number with decimal precision. Use:

Double.parseDouble() or Float.parseFloat()

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.