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: Chris Kane <email@hidden>
- Date: Tue, 17 Jan 2006 09:25:03 -0800
On Jan 16, 2006, at 5:37 PM, Mike Zornek wrote:
Does anyone have any advice on the best column type to use to
handle money
in a Core Data Application.
Longer term I'd like it to be an international app as well, and be
able to
store money based on system preferences.
To address the last bit some: It's likely you should be storing a
currency indicator of some kind, possibly the ISO currency code,
along with the value, in another field/column. If you just store the
value now, you'll have trouble later when you ask yourself "3.76
WHAT?". Currency is not one of those things, unfortunately, that can
be converted to some canonical units/reference frame, like measures
of length or time (where you don't need to store the units). Of
course, there _are_ specialized cases where there is only one fixed
answer possible ("Payment must be in U.S. Dollars."), so you have to
think about the application domain you're dealing with.
As far as "based on system preferences" and user input: it is
reasonable to default to presume in UI that the user is typing in a
value based on their preferred currency, but it is not reasonable to
assume the user will never (or never want to) type anything else. At
a minimum you should give indication of what currency they are
providing a value for, with a static text field next to the input
field. Better is to give the user a popup button or a text field or
combo box or whatever so they can choose/set the currency too. Also
keep in mind that currency symbols are ambiguous, and should be used
with some caution ("$" to a user in the U.S. means a different unit
than "$" in Australia etc.).
Also, don't assume (in UI or storage) that money values mean "two
decimal places" -- that isn't universal. In the U.S. it is common to
run across dollar amounts with fractional cents in commerce and
government (for example, price per unit in bulk or an employee's
hourly pay rate or the price of a share of something or property tax
levies per dollar value, and so on).
Finally, some applications may require even more data to be saved
with a currency value to make it useful, such as a date(time); for
example, so that currency conversions can be done later based on a
database of historical data. Probably the people in that kind of
situation will know how to deal with it.
So at a minimum you should save a currency indicator (the units) and
display something to the user about the units.
Chris Kane
Cocoa Frameworks, Apple
_______________________________________________
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