convert string with decimal to integer

Solved 1 Answers 107 Views Programming
0 1
I am given a string (100.0). I need to convert that to int. How do I do that?

When I do Integer.parseInt(). I am getting below error.

java.lang.NumberFormatException: For input string: "100.0"

1 Answer

Best answer

You can achieve this by using java.lang.Double class


Double valueToDouble = Double.parseDouble("100.0");
int valueint = valueToDouble .intValue();
answered by

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
Anti-spam verification:
To avoid this verification in future, please log in or register.

Top Contributors