Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting Error java.lang.NumberFormatException: For input string: "16.0"

Tags:

java

I want to convert the cell value into int value so i am trying following code:

for (int chk1 = 1; chk1 < m; chk1++ ) {
   int intCounter = Integer.parseInt( cells.checkCell(chk1,0).getValue().toString() );
}

But it is accepting only the string format if there is any number then it is giving me

java.lang.NumberFormatException

How can I avoid this? Is there any way to convert all data into integer or into String or vice versa?

like image 997
John D Avatar asked Dec 04 '22 20:12

John D


2 Answers

The problem is the ".0" bit. Integer.parseInt only allows digits so the decimal point is illegal, hence the NumberFormatException.

You should make sure that your input really is an integer (i.e. "16"), or if you actually want to allow decimals then use Double.parseDouble or Float.parseFloat.

like image 138
Cameron Skinner Avatar answered Jan 12 '23 00:01

Cameron Skinner


Take a look at Double.intValue()

like image 39
Oh Chin Boon Avatar answered Jan 11 '23 23:01

Oh Chin Boon