I have a UITextField in my app that accepts decimal amounts for prices (i.e., 123.45). This field is stored in Core Data as an integer.
The code I have that doesn’t work is:
[self.managedObject setValue:[textField floatValue]*100 forKey:@"price"]
And I can’t quite figure out how to make this work. Any ideas?
Thanks!
the answer is
[[self managedObject] setValue:[NSNumber numberWithInteger:([textField floatValue]*100)] forKey:@"price"]You should be using NSDecimalNumber for currency as it handles decimals without floating point issues.