> On Sat, Mar 26, 2011 at 8:15 PM, BareFeetWare <list....@barefeetware.com> 
> wrote:
>> Can you store all money amounts as integers, as the cents value? That is 
>> exact, searchable etc.

On 27/03/2011, at 1:27 PM, Patrick Earl wrote:

> That is true, but then when you are formulating generic queries within
> a place such as an ORM like NHibernate, you would need to figure out
> when to translate the user's "100" into "10000".

You can keep all internal transactions as integers, so there are no float 
rounding errors. You only have to translate the final figures if you want to 
display to the user as dollars. You can do this in selects or use views to 
convert the data if needed. For instance:

create table Staff
(       ID integer primary key not null
,       Name text collate nocase not null
,       Salary integer -- in cents
)
;
create view "Staff Dollars"
as
select
        ID
,       Name
,       round(Salary/ 100.0, 2) as Salary
from "Staff"
;

> As well, if you multiplied numbers, you'd need to re-scale the result.  For 
> example, (1 * 1) would be (100 * 100 = 10000), which is 1 * 1 = 100. :(

I can't think of any reason for multiplying two money amounts. You would only 
ever multiple a money amount by a plane number, so you only ever have to /100 
if you want to present your final answer in dollars. I do this for invoice 
totals, tax return calculations and similar.

Tom
BareFeetWare

--
iPhone/iPad/iPod and Mac software development, specialising in databases
develo...@barefeetware.com
 --
Comparison of SQLite GUI tools:
http://www.barefeetware.com/sqlite/compare/?ml

_______________________________________________
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to