How to convert a char array containing double value to double variable?

狂风中的少年 提交于 2019-12-25 08:16:37

问题


Sorry, if I am not posting my try. I have no idea how to approach this.

I want charArr to be converted to doubleVal:

char[] charArr = {'1'','1','.','1','1','1'};
double doubleVal = 11.11;

回答1:


here is a hint

  • convert the char array to string. ( see String.valueOf method)
  • convert the string to double value ( see Double.parseDouble)



回答2:


Something like this:

StringBuilder sb = new StringBuilder();
sb.append(charArr);
Double d = Double.parseDouble(sb.toString());



回答3:


Something like that: you can try this

for(int i=0; i<charArr.length;i++){
char c =charArr[i];
Double d = Double.parseDouble(c.toString());
// do some operation
}


来源:https://stackoverflow.com/questions/23026392/how-to-convert-a-char-array-containing-double-value-to-double-variable

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