views:

106

answers:

2

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       = [NSNumber 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"];
}
A: 

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

Jesse Naugher
+1  A: 

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

kubi
Long day, I don't know how I didn't notice I had withInt. Thank you so much.
Oh Danny Boy
Make sure you set the entity's Attribute type to "Double" in your model as well.
falconcreek