2

In array I do have two values value1="234.3423" value2="12.60348" i need to pass this value to varable double x, double y;

How to do this

Thanks in advance.

kiran kumar
  • 1,349
  • 4
  • 21
  • 40

2 Answers2

6

First, you need to turn them into the number (which you're giving in C string syntax here) into an NSString:

char *value1 = "234.3423";
NSString *string1 = [NSString stringWithUTF8String:value1];

Then, simply do this:

double x = [string1 doubleValue];

That's it. If the simple number parsing of NSString is not enough for you, you will need to look into NSNumberFormatter.

DarkDust
  • 90,870
  • 19
  • 190
  • 224
  • double x=[[myArrayList objectAtIndext:1] doubleValue]; double y=[[myArrayList objectAtIndext:2] doubleValue]; Do i do like this . – kiran kumar Oct 25 '10 at 07:13
  • @kiran kumar: Yes, that's perfectly fine. But note that indexes start with 0. So the first element in the array has index 0, the second 1, etc. – DarkDust Oct 25 '10 at 10:19
0
double x=[[myArrayList objectAtIndext:1] doubleValue]; 
double y=[[myArrayList objectAtIndext:2] doubleValue]; 

Hope its works for me :D

If not help me any another easy way.

kiran kumar
  • 1,349
  • 4
  • 21
  • 40