On Sun, 13 Apr 2008, Aladdin Lampé wrote:

Thank you Nicolas for your answer. I understand that an int64 certainly
gives me enough precision in the general case. Now what am I supposed to
do if the user decides to add a virtual 4 decimal digits number to another
number which has only 2 decimal digits? I should first identify this and
then multiply by 100 the second number in order to be able to use sqlite
built-in operators and functions... Not so simple, I think... And in my
case, it is the user who determines the precision he desires for each
number within the application, so I cannot have the precision fixed once
for all like you suggest.

Aladdin,

  The question of how to represent currency in a computer program has been
around since computers added business applications to calculating firing
solutions for artillary. I've been aware of the problem when writing dbms
applications since the early days of DOS.

  There is no BCD data type in SQLite, but you may find an external library
in the language of your choice that will do calculations for you. Another
approach (less elegant but workable) is to add 0.05 to all values with two
fractional monetary digits. Since the answer is usually truncated rather
than rounded, this old trick will give you results accurate to the penny.

  If the application has currencies as a critical element, then you do want
to fix the precision to the smallest unit.

Rich

--
Richard B. Shepard, Ph.D.               |  Integrity            Credibility
Applied Ecosystem Services, Inc.        |            Innovation
<http://www.appl-ecosys.com>     Voice: 503-667-4517      Fax: 503-667-8863
_______________________________________________
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to