代码之家  ›  专栏  ›  技术社区  ›  sujith1406

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

  •  16
  • sujith1406  · 技术社区  · 14 年前

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

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

    然而,当i NSLog coordinate.latitude和coordinate.longitude时,它会下降0.00000

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

    有什么问题吗???

    1 回复  |  直到 14 年前
        1
  •  9
  •   Marcelo Cantos    11 年前

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

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