开发者

Core Data: NSManagedObject adding values "forKey" - NSNumber truncates. Alternative?

I understand that NSNumber cannot go beyond 1/10ths place. What can I use as an alternative to add a doubles (longitude/latitude) into Core Data? Using double directly does not work and NSNumber truncates the value.

NSManagedObject *newManagedObject = [NSEntityDescription 
                                     insertNewObjectForEntityForName:[entity name]
                                     inManagedObjectContext:managedObjectContext];

if ([locObj valueForKey:@"latitude"]        != NULL) {
    NSNumber    *latitude       = [开发者_如何学JAVANSNumber numberWithInt:[[locObj valueForKey:@"latitude"] doubleValue]];
    [newManagedObject setValue:latitude forKey:@"latitude"];
}
if ([locObj valueForKey:@"longitude"]       != NULL) {
    NSNumber    *longitude      = [NSNumber numberWithInt:[[locObj valueForKey:@"longitude"] doubleValue]];
    [newManagedObject setValue:longitude  forKey:@"longitude"];
}


Why don't you use [NSNumber numberWithDouble:x] ?


you might take a look at NSDecimalNumber ? Otherwise i believe you might have to deal with the rounding.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜