How to parse string to int?
my string is 743.4445 and I want it to show 743 so it has to parse to double and then parse to int so I try 开发者_Python百科like this
(int)(Double.valueOf(743.4445);
(actually 743.4445 is from server thus I don't know exactly value)
what am I suppose to do?
why not google "java get whole number"
double d = Double.valueOf(s.trim()).doubleValue();
Heck, for that matter why not use IndexOf on the string looking for the .? :)
Please try this.
Store this value in one string and try this.
String number = "743.4445";
(int)Double.parseDouble(number)
Why not use NumberFormat.setParseIntegerOnly(boolean value)
method?
Example:
String s = "743.5555";
NumberFormat format = NumberFormat.getInstance();
format.setParseIntegerOnly (true);
int value = format.parse(s).intValue();
精彩评论