How can I store a currency other than NSDecimalNumber?
I am using Realm.io database for iOS. I am creating an RLMObject and only supports NSInteger, CGFloat, int, long, float, and double
numbers, but not NSDecimalNumber
. I thought about using it double
, but saw that it has rounding errors, less than float
that, but it still has them. What would be the best way to store currency?
source to share
One of your options is to use NSString for storage. The basic plan for what you need to do would be:
- Get the string "14.10" from
NSDecimalNumber
- Save to Realm
When you want to get it back you will pull the object to get the string back again and then you will need to run + (NSDecimalNumber *)decimalNumberWithString:(NSString *)numericString
which will set you back to your value
source to share