Reputation: 11749
I have Float values stored in Core-Data. What is the code to use to read these values in an NSstring ?
Upvotes: 1
Views: 1344
Reputation: 687
Well, assuming that you mean your Core Data entity has an attribute of type float, you could simply access that field after you perform a fetch of that object.
[[self managedObjectContext] fetchObjectsForEntityName:@"EntityName" withPredicate:
@"(attribute LIKE[c] 'value') AND (attribute2 > %@)", someValue];
You could then put this in string format with this:
NSString* myNewString = [NSString stringWithFormat:@"%f", [[managedObject floatAttribute] floatVal]];
Upvotes: 0
Reputation: 90117
Core-Data uses NSNumber objects to store the float value.
To get the 'raw' float value and put it into a string you would use something like this.
NSNumber *floatNumber = [managedObject valueForKey:@"myFloatValueKey"];
float myFloat = [floatNumber floatValue];
NSString *floatString = [NSString stringWithFormat:@"%f", myFloat];
Maybe a NSNumberFormatter would be useful.
Upvotes: 5