On 9 Dec 2013, at 4:12pm, RSmith <rsm...@rsweb.co.za> wrote: > On 2013/12/09 15:32, Simon Slavin wrote: >> Second, multiplying by 100 and defining columns as INTEGER to store money to >> two places /is/ the correct solution. This means that arithmetic will >> automatically be done to two places. You will have to test whether results >> are rounded or truncated when you do tax calculations but better still would >> be to explicitly use round() when any dividing is done. > > I cannot agree with this - maybe if you are storing a simple personal budget > on your home PC, but in any real-world financial institution or corporate > finance system and even the corner-shop up your street, those milli-dollars > (if you will) behind the cents can amount to substantial amounts over some > transactions and/or time and should not ever be lost to rounding. (In most > large bank-systems, the accumulated transactional amounts less than 1 cent > amounts to several million per month)
Actually, I used to work with banking software and I can tell you how it's done for real. And the answer is that they really do use integers for the smallest tradable unit of currency. So now days, for both the US dollar and the GB pound they would use hundredths, just as stated above. Back when I did it Lira was done with four places (ten thousandths) because by law it was theoretically possibly to trade a ten thousandth of a Lira. And when the half-penny existed in Britain we had to use two-hundredths of a pound ! The reason integers were used was that banks can't be accused of snaffling the fractions. So all add/subtract/multiply is done with the integers. And division must always have an explicit round() or truncate() in to make it clear what they intended the program to do. Some of the apps I worked with had a hacked compiler which had had automatic coercion removed so the programmer couldn't forget to use coercion functions. Simon. _______________________________________________ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users