Return-Path: Delivered-To: apmail-couchdb-user-archive@www.apache.org Received: (qmail 98734 invoked from network); 1 Sep 2009 09:18:49 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 1 Sep 2009 09:18:49 -0000 Received: (qmail 11590 invoked by uid 500); 1 Sep 2009 09:18:48 -0000 Delivered-To: apmail-couchdb-user-archive@couchdb.apache.org Received: (qmail 11504 invoked by uid 500); 1 Sep 2009 09:18:48 -0000 Mailing-List: contact user-help@couchdb.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: user@couchdb.apache.org Delivered-To: mailing list user@couchdb.apache.org Received: (qmail 11494 invoked by uid 99); 1 Sep 2009 09:18:47 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 01 Sep 2009 09:18:47 +0000 X-ASF-Spam-Status: No, hits=1.5 required=10.0 tests=SPF_PASS,WEIRD_PORT X-Spam-Check-By: apache.org Received-SPF: pass (nike.apache.org: domain of robert.newson@gmail.com designates 209.85.220.227 as permitted sender) Received: from [209.85.220.227] (HELO mail-fx0-f227.google.com) (209.85.220.227) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 01 Sep 2009 09:18:37 +0000 Received: by fxm27 with SMTP id 27so3453505fxm.11 for ; Tue, 01 Sep 2009 02:18:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:in-reply-to:references :date:message-id:subject:from:to:content-type :content-transfer-encoding; bh=zvoSPqPBFm65Sul2m+MfMF1FTRszV/XSfz6bYNGE+Bg=; b=clefv1dmdjqTLG43Q8GKsfQEp2IuqTbIOfic+Etgt0oqagw8rEWU+zYEHv+K7txhJx OZzUoHFwpp30CvOQVlicw8KNBYZ6EIAVGoFQWYwM5eLomYfTLhJR2B/58bgamqvO5f/Y YzEHKpMLqeEWgUdGWDluPyno2uTxH6RJoHCpU= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type:content-transfer-encoding; b=LDJijGL2AQrWmXFwQhWGXZ3vvFixQ63hYivus/MoxFEH6XsGVwjhAiqfTrzljUOyI7 Yw7f7o1wKSRZGWVB4h/2znw7hguZxaHQY1gKc5NnQLCyM0M6Owwq5gIBww2mwIfwH281 CaHeXBiMb/qxm/YX52UCWNaWiqxeUfxDr4ufQ= MIME-Version: 1.0 Received: by 10.204.154.154 with SMTP id o26mr5321879bkw.107.1251796697091; Tue, 01 Sep 2009 02:18:17 -0700 (PDT) In-Reply-To: <98a246a10909010158v57cf5eb8r6a98b07933a14b7f@mail.gmail.com> References: <98a246a10909010158v57cf5eb8r6a98b07933a14b7f@mail.gmail.com> Date: Tue, 1 Sep 2009 10:18:17 +0100 Message-ID: <46aeb24f0909010218u3c4f8d4bp45ae6a377d9f26c7@mail.gmail.com> Subject: Re: Is fixed precision arithmetic possible in couchdb python? From: Robert Newson To: user@couchdb.apache.org Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Virus-Checked: Checked by ClamAV on apache.org Multiply your numbers by the amount of precision you need and use integers (*1000 for 3 d.p)? Using floating point to store money amounts seems fraught with rounding errors. B. On Tue, Sep 1, 2009 at 9:58 AM, Metin Akat wrote: > /* Paste this in a code editor to have code highlighting */ > > /* Here is my Map function */ > function(doc) { > =A0if (doc.type =3D=3D "Transaction") { > =A0 =A0for (var i =3D 0; i < doc.accounts.length; i++) { > =A0 =A0 =A0emit(doc.accounts[i].account, > =A0 =A0 =A0doc.accounts[i].value * > =A0 =A0 =A0doc.accounts[i].operation > =A0 =A0 =A0); > =A0 =A0} > =A0} > } > /* 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) { > =A0return sum(values); > =A0} > > > /* When I visit: > http://localhost:5984/nola7accounting/_design/accounting/_view/balance?gr= oup=3Dtrue > I get this. The 13.05(9) is the sum of 5.03 + 8.03 (so is -13.05(9), > only it's negative). */ > {"rows":[ > {"key":"5cf15107d977498ec4003dca0d44c579","value":-13.059999999999999}, > {"key":"b4b0c38efd4ff4c27fc63d24ae981f60","value":13.059999999999999} > ]} > > /* But when I visit: > http://localhost:5984/nola7accounting/_design/accounting/_view/balance > 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 > 0), > =A0but here is what I get: */ > {"rows":[ > {"key":null,"value":-8.881784197001252e-16} > ]} > > /* 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: > http://books.couchdb.org/relax/receipts/banking > The example there is nice and working, but it works with whole numbers > (integers). > So, the first question is... Is there some way of working with fixed > precision numbers in CouchdB? > And the further question is... =A0How good is CouchDB (or any JSON > storage) for an accounting application? > =A0*/ >