Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert a string value into an int [duplicate]

How to convert string value into int? I am getting number format exception.

String s = "20.00";
int i = (Integer.parseInt(s));
System.out.println(i);

Result should be like i=20.

like image 787
user2920003 Avatar asked Dec 12 '22 10:12

user2920003


1 Answers

What about:

int i = (int) Double.parseDouble(s);

Of course, "20.00" is not in a valid integer format.

like image 97
arshajii Avatar answered Dec 28 '22 23:12

arshajii