couchdb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Metin Akat <>
Subject Is fixed precision arithmetic possible in couchdb python?
Date Tue, 01 Sep 2009 08:58:15 GMT
/* Paste this in a code editor to have code highlighting */

/* Here is my Map function */
function(doc) {
  if (doc.type == "Transaction") {
    for (var i = 0; i < doc.accounts.length; i++) {
      doc.accounts[i].value *
/* Here the value is the money transferred to or from an account and
the operation an integer (1 or -1) showing the type (credit debit)
of the operation */

/* This is the reduce */
function(keys, values) {
  return sum(values);

/* When I visit:
I get this. The 13.05(9) is the sum of 5.03 + 8.03 (so is -13.05(9),
only it's negative). */

/* But when I visit:
In the accounting world, this should return 0 as it is the sum of all
values (and the sum of all operations in a financial system must be
 but here is what I get: */

/* OK, the above is is something close to 0, but the question is...
how good is this for a financial software system?
The situation is the same, no matter if I store floats or strings
(which would represent decimals). This is probably the result
of the weak typing in javascript (JSON).
I wrote this view following along the "Banking" chapter of the CouchDB
book, here:
The example there is nice and working, but it works with whole numbers
So, the first question is... Is there some way of working with fixed
precision numbers in CouchdB?
And the further question is...  How good is CouchDB (or any JSON
storage) for an accounting application?

View raw message