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);
Share:
19,207
user887738
Author by

user887738

Updated on July 27, 2022

Comments

  • user887738
    user887738 almost 2 years

    I am developing an android app. I need to convert string to double. How can I do it?

  • Ray Toal
    Ray Toal over 12 years
    I think the OP wanted a small-d double, but boxing is okay.
  • hansvb
    hansvb over 12 years
    better to catch only NumberFormatException