使用[NSNumber numberWithDouble:]将double转换为NSNumber

suj*_*406 16 iphone nsnumber

有一个坐标对象有三个变量纬度(NSNumber),经度(NSNumber)和时间(NSDate),为了检查我的模拟器上的程序,我给了下面的代码

[coordinate setLatitude:[NSNumber numberWithDouble:23.234223]];
[coordinate setLongitude:[NSNumber numberWithDouble:73.234323]];
Run Code Online (Sandbox Code Playgroud)

但是当我NSLog coordinate.latitude和coordinate.longitude时,它会显示0.00000

NSLog(@"cordlat :  %f",coordinate.latitude);
NSLog(@"cordlong :  %f",coordinate.longitude);
Run Code Online (Sandbox Code Playgroud)

可能是什么问题???

Mar*_*tos 9

你不能打印NSNumber%f.您可以执行以下操作之一:

  1. NSLog(@"cordlat : %@", coordinate.latitude);
  2. NSLog(@"cordlat : %f", coordinate.latitude.doubleValue);