How can I convert string to double? [duplicate]

∥☆過路亽.° 提交于 2020-02-24 14:10:30

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!