Communities for your favorite technologies. Explore all Collectives
Stack Overflow for Teams is now called Stack Internal. Bring the best of human thought and AI automation together at your work.
Bring the best of human thought and AI automation together at your work. Learn more
Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
How to convert string value into int? I am getting number format exception.
number format exception
String s = "20.00"; int i = (Integer.parseInt(s)); System.out.println(i);
Result should be like i=20.
i=20
20.60
What about:
int i = (int) Double.parseDouble(s);
Of course, "20.00" is not in a valid integer format.
"20.00"
Add a comment
String s = "20.00";
is not valid Integer value that is the reason its throwing NumberFormatException.
Integer
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.
Double
Float
int
i.e. int I = (int) Double.parseDouble(str);
int I = (int) Double.parseDouble(str);
Start asking to get answers
Find the answer to your question by asking.
Explore related questions
See similar questions with these tags.
20.60what do you expect the integer to be?