开发者

How can I convert string to double? [duplicate]

This question already has answers here: Converting String to Double in Android 开发者_StackOverflow社区 (9 answers) Closed 3 years ago.

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");
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜