How can I convert string to double? [duplicate]
I am developing an android app. I need to convert string to double. How can I do it?
You just need this :
double d=Double.parseDouble(myString);
If your String
value cannot be parsed to double it will throw NumberFormatException
. So better you put the parseDouble
statement inside try catch block.
here is the example
try{
double dbl = Double.parseDouble("99.882039");
catch(NumberFormatException ex){
// handle exception
}
double d = Double.parseDouble(theString);
That's not a thing of android but if you're sure you string can be expressed as a double you can do it like this with simple Java:
Double.valueOf("1.2");
精彩评论