RE: Recommendation for keeping track of money in Core Data
RE: Recommendation for keeping track of money in Core Data
- Subject: RE: Recommendation for keeping track of money in Core Data
- From: Jeff Laing <email@hidden>
- Date: Tue, 17 Jan 2006 13:44:29 +1100
> Well, it seems that you have three options: float, double, and
> decimal number.
>
> It's going to depend on what your needs are. If you're doing personal
> finance program, float is probably fine; if you're doing budgetary
> accounting for a country, you'd probably want to lean toward double
> or even decimal number.
> For most situations where you need to deal with money, I'm guessing
> float is going to be fine. 32 bits of precision if your mantissa is
> only 2 should be plenty for most applications.
Irrespective of the amounts of money involved, its never a good idea to use
'float' to store currency, because there are common "decimal" numbers which
do not have an accurate floating point representation.
You end up dealing with "23.29999999999999999" or "23.300000000001" instead
of "23.3".
Which means that any equality checks you do, or comparisons you do, may have
results you don't expect, whether it be in small sums, or large ones.
Its not a question of "number of significant places" - there are numbers
that cannot be represented accurately in binary floating point.
As I recall, people bitched and moaned about this problem in the OSX
calculater way back with 10.0 was first released. Floating point sucks, I
can't say it strongly enough.
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden