incubator-couchdb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Metin Akat <akat.me...@gmail.com>
Subject Re: sum function in reduce with precision problems?
Date Sat, 12 Dec 2009 23:01:33 GMT
I am writing financial software with CouchDB backend.
So far the best solution for me is to use rationals for arithmetic.
In order to achieve this I use couchdb-python view server. I store
rationals as strings in the database, for example "1/2", "3/4" etc.
Then I use Python's fractions module to convert them to rationals and
do arithmetic with them. It's easy like a piece of cake:

>>> from fractions import Fraction as F
>>> F('1/2') + F('3/4')
Fraction(5, 4)


The "store cents" method works for simpler tasks, but if you need to
have things like different currencies it becomes a nightmare.

I am very much interested to find out if someone knows better solution
(one that could fit in the standard javascript view server), but so
far I don't think that there is such. And my solution seems to work
fine for now.

Mime
View raw message