AlexDenisov / iActiveRecord

ActiveRecord for iOS without CoreData, only SQLite
http://alexdenisov.github.com/iActiveRecord/
MIT License
354 stars 50 forks source link

NSDecimalNumber and new primitive types #30

Closed mgod closed 11 years ago

mgod commented 11 years ago

Hey Alex,

I think iActiveRecord should use a different method for dealing with NSDecimalNumber now that primitive numeric types are available. Now that you can have floating point values through a method other than NSDecimalNumber, I think we should move to using NSDecimalNumber for currency only (which is really what it's there for). Given this, we should really store NSDecimalNumbers as string values in sqlite to keep the base-10 math precision correct.

I'm happy to go ahead and write up a patch if this sounds reasonable to you.

Marshall

AlexDenisov commented 11 years ago

I've used NSDecimalNumber to provide ability for double data type, but now we can use NSNumber's objcType and primitive types for this issue. And I think that you are only one who use this library for this purpose :smile: So go ahead and do it :+1:

aaronrogers commented 11 years ago

I'm doing some lat long stuff in my app and I don't know which type to use. CoreLocation uses doubles for everything and they're all floating point values.

mgod commented 11 years ago

If you're using a recent enough version of iActiveRecord that the double type is available, use that instead of NSDecimalNumber. NSDecimalNumber is intended primarily for currency math where base-10 math is critically important.

aaronrogers commented 11 years ago

Ok, I'll check it out. I'm using 1.3.2 with Cocoapods. How does it handle null values in the DB?

mgod commented 11 years ago

With that version, you'll need to use NSDecimalNumber to save double values. Null values will get returned as empty strings, which is fixed in the latest dev version.

aaronrogers commented 11 years ago

Thanks. Can't wait for the podspec to be updated.