Core Data - Decimal Type for Currency

早过忘川 提交于 2020-08-26 16:32:07

问题


I read in a recent post that the Decimal data type is the best to use in Core Data to model currency since it doesn't have floating point issues.

I've searched the apple docs and google and can't seem to find any documentation on using the Decimal type.

Does anyone have a link to documentation on it?

Thanks!


回答1:


Use "Decimal" as the attribute type in your data model and NSDecimalNumber as the object type in your code.




回答2:


The 'decimal' type in Core Data relates to the Cocoa type NSDecimalNumber, and lo, here is its documentation: NSDecimalNumber documentation :-)




回答3:


Its because we don't want to get things like $9.9999999998 instead of $10.

More Details:

https://stackoverflow.com/a/17107017/1239426



来源:https://stackoverflow.com/questions/2376853/core-data-decimal-type-for-currency

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!