Reputation: 5176
Let's say that I have these variables:
float xx= 99.33f;
int yy=0;
I want to convert xx to yy by removing the digit marks, so that yy will be the number 9933, preferably with a single line statement. How is this possible?
Upvotes: 0
Views: 155
Reputation: 1315
Try using this. its two line but, it might work.
float xx= (float) 99.33;
String yys=String.valueOf(xx).replace(".", "");
int yy=Integer.parseInt(yys);
Upvotes: 3
Reputation: 2575
Just the easiest way that comes up for me, but I assume that there could be easier ways to do that. But you can make it like a function.
String s = Float.toString(xx);
String[] temp=s.split("\\.");
yy=Integer.parseInt(temp[0]+temp[1]);
Upvotes: 3