问题
I am developing an android app. I need to convert string to double. How can I do it?
回答1:
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.
回答2:
here is the example
try{
double dbl = Double.parseDouble("99.882039");
catch(NumberFormatException ex){
// handle exception
}
回答3:
double d = Double.parseDouble(theString);
回答4:
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");
来源:https://stackoverflow.com/questions/7239542/how-can-i-convert-string-to-double