How can I convert string to double?
19,207
Solution 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.
Solution 2
here is the example
try{
double dbl = Double.parseDouble("99.882039");
catch(NumberFormatException ex){
// handle exception
}
Solution 3
double d = Double.parseDouble(theString);
Author by
user887738
Updated on July 27, 2022Comments
-
user887738 almost 2 years
I am developing an android app. I need to convert string to double. How can I do it?
-
Ray Toal over 12 yearsI think the OP wanted a small-d double, but boxing is okay.
-
hansvb over 12 yearsbetter to catch only NumberFormatException