Reputation: 863
How do I convert String in form xx:yy
into integer form xxyy
or float form xx.yy
For example If I have the following string.
String x = "10:30"
How do I get integer 1030
or float value 10.30
?
Upvotes: 1
Views: 191
Reputation: 794
String xInt = x.replace(":","");
Integer.parseInt(xInt);
String xFloat = x.replace(":",".");
Float.parseFloat(xFloat);
Upvotes: 1
Reputation: 1622
String[] parts = x.split(":");
float value = Integer.parseInt(parts[0]) + (float)Integer.parseInt(parts[1])/100;
or
Float.parseFloat(x.replaceAll(":", "."));
Upvotes: 2