How to convert a char array containing double valu

2019-09-07 00:13发布

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;

3条回答
We Are One
2楼-- · 2019-09-07 01:04

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
}
查看更多
做个烂人
3楼-- · 2019-09-07 01:09

Something like this:

StringBuilder sb = new StringBuilder();
sb.append(charArr);
Double d = Double.parseDouble(sb.toString());
查看更多
做自己的国王
4楼-- · 2019-09-07 01:14

here is a hint

  • convert the char array to string. ( see String.valueOf method)
  • convert the string to double value ( see Double.parseDouble)
查看更多
登录 后发表回答