converting double into NSNumber using [NSNumber numberWithDouble:]
Asked Answered
S

1

16

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???

Sleave answered 24/11, 2010 at 11:36 Comment(3)
what type coordinate is?Undesigning
coordinate is an object of class Coordinate which has three vars latitude,longitude and time,this object is to be used with coredata,so i defined the latitude & longitude as NSNumber typeSleave
question title and question description doesn't seem to match. :SInane
L
10

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);
Lytta answered 24/11, 2010 at 11:39 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.