Vinoth
Vinoth

Reputation: 311

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

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;

Upvotes: 1

Views: 6226

Answers (3)

Tamil
Tamil

Reputation: 19

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
}

Upvotes: 0

user3159253
user3159253

Reputation: 17455

Something like this:

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

Upvotes: 2

stinepike
stinepike

Reputation: 54742

here is a hint

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

Upvotes: 3

Related Questions