본문 바로가기

Java

[JAVA] W/System.err: java.lang.NumberFormatException: For input string:

String amount = "72946.0000"

 

String 타입으로 소숫점 .0000 달린 수를 DB에서 받아왔는데.

 

이 값을 int형으로 사용하려고 Integer.partInt(amount)했는데 

 

W/System.err: java.lang.NumberFormatException: For input string:

이런 숫자형 에러가 나왔는데.

 

https://stackoverflow.com/questions/19303351/java-lang-numberformatexception-for-input-string-10-0

 

java.lang.NumberFormatException: For input string: "10.0"

This code must validate input data from the findActions() method: try { System.out.println(findActions(lookingArea.substring(0, right)));// always printing valid number string Integer.pars...

stackoverflow.com

여기 마지막 댓글에서 

 

(int)Double.parseDouble(amount)

 

이렇게 해보라고 해서 해결되었다. 감사합니다.

 

 

소숫점 때문에 Double형을 먼저 거친 후 int로 형변환해서 해결된듯 합니다.

'Java' 카테고리의 다른 글

JAVA 오늘 날짜 어제 내일 작년 등 구하기  (0) 2020.01.17
[Java] try-with-resources 예외처리  (0) 2019.10.01