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?
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
.
Take a look at Double.intValue()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With