Zeyad Gasser
Zeyad Gasser

Reputation: 1546

String formatting potential string doubles or integer into integers

I receive a string from a server that sometimes is a double and sometimes is an integer. And i need it to be an integer. When i do a Integer.parseInt(confusedStringNumber) If its a double, it throws a Number format exception. Is there a way to format the string to drop all decimal places whether they exist or not ? Thanks

Upvotes: 0

Views: 68

Answers (2)

Jorge Sanchez
Jorge Sanchez

Reputation: 1629

int i = (int)Float.parseFloat("1.0");
int j = Float.valueOf("1.0").intValue();

Upvotes: 4

Related Questions