Convert String to double

SKB picture SKB · Aug 22, 2011 · Viewed 8.9k times · Source

Is there way to convert a string to double. This is how i did.

String s = b.getText().toString();
       double d = Double.parseDouble(s);

It gives NumberFormatException

Answer

CommonMan picture CommonMan · Aug 22, 2011

Try this

String s = b.getText().toString(); double d = Double.valueOf(s.trim()).doubleValue();