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
.
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
.
What about:
int i = (int) Double.parseDouble(s);
Of course, "20.00"
is not in a valid integer format.
String s = "20.00";
is not valid Integer
value that is the reason its throwing NumberFormatException
.
Format your number using either Double
or Float
then using narrow casting cast you number to int
but you may loose precision if exists.
i.e. int I = (int) Double.parseDouble(str);
© 2022 - 2024 — McMap. All rights reserved.
20.60
what do you expect the integer to be? – Marjoriemarjory