3 ms·
One additional answer on this: money isn't a float. The dollar, for example, is an integer number of cents. A good way to represent this is using Fowler's Quan
by wpietri 13y ago
One additional answer on this: money isn't a float. The dollar, for example, is an integer number of cents.
A good way to represent this is using Fowler's Quantity pattern:
http://martinfowler.com/eaaDev/quantity.html http://martinfowler.com/eaaDev/quantity.html
That lets you encapsulate the ton of special behavior that money has. For example, for most software money can't be created or destroyed, just transfered.
- sandGorgon 13y agoThis is very interesting - is this kind of a pattern used in real financial software, or is this just an idea ?
- dan15 13y agoSome software will use a specific money or decimal type (some databases support these). Others will store money as an integer in the smallest units needed. ie. if you only need dollars to the nearest cent, store the number as cents ($1.50 is stored as 150)