Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

converting double into NSNumber using [NSNumber numberWithDouble:]

there is a coordinate object with three variables latitude(NSNumber) ,longitude(NSNumber) and time(NSDate),for checking the program on my simulator,i gave the folowing code

[coordinate setLatitude:[NSNumber numberWithDouble:23.234223]];
[coordinate setLongitude:[NSNumber numberWithDouble:73.234323]];

however when i NSLog coordinate.latitude and coordinate.longitude,it diplays 0.00000

NSLog(@"cordlat :  %f",coordinate.latitude);
NSLog(@"cordlong :  %f",coordinate.longitude);

what can be the problem???

like image 217
sujith1406 Avatar asked Nov 24 '10 11:11

sujith1406


1 Answers

You can't print an NSNumber with %f. You can do one of the following:

  1. NSLog(@"cordlat : %@", coordinate.latitude);
  2. NSLog(@"cordlat : %f", coordinate.latitude.doubleValue);
like image 77
Marcelo Cantos Avatar answered Nov 12 '22 14:11

Marcelo Cantos