Return-Path: X-Original-To: apmail-couchdb-user-archive@www.apache.org Delivered-To: apmail-couchdb-user-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id C4A8D1040C for ; Fri, 15 Nov 2013 12:27:18 +0000 (UTC) Received: (qmail 29771 invoked by uid 500); 15 Nov 2013 12:27:16 -0000 Delivered-To: apmail-couchdb-user-archive@couchdb.apache.org Received: (qmail 29735 invoked by uid 500); 15 Nov 2013 12:27:16 -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 29723 invoked by uid 99); 15 Nov 2013 12:27:15 -0000 Received: from minotaur.apache.org (HELO minotaur.apache.org) (140.211.11.9) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 15 Nov 2013 12:27:15 +0000 Received: from localhost (HELO mail-la0-f51.google.com) (127.0.0.1) (smtp-auth username rnewson, mechanism plain) by minotaur.apache.org (qpsmtpd/0.29) with ESMTP; Fri, 15 Nov 2013 12:27:14 +0000 Received: by mail-la0-f51.google.com with SMTP id ec20so2623217lab.24 for ; Fri, 15 Nov 2013 04:27:12 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type:content-transfer-encoding; bh=GvvV9Wpg8dreEwxMGdeGC99Fym1frAZWJZXmO2XtM9g=; b=OrlRjTm5Wvo69CgUcwiiiu8sQA1wOYo7ZJA2jf1/wD/iVlt0Gvv2WkShDahvAuglzS x25iyYEUqZg2GBKglik4uFz10qyaTihWOq9kcuLkZuHcbKvyLoj8MbQZ7Qe8eaJb83Yz IOwfDjPzejPbwFWeZG3CrQCXKLBtEyuvtXFWJyxR7vuFmmiDT3aTpK+WmWdoiSfRhVX/ /6eBoNtCTwPi0sbY2ZNfNoe76O8TAuOph7mESJap0odz+qd8rF2NLltmkc9jX1CDyqKX ZIbsg47kX0i4SVpiPOH6isUZA+H9nxtcWqGfKTRpdQiLv1ESqLTGvMvouyekAHy6aosq 4s0Q== MIME-Version: 1.0 X-Received: by 10.112.210.136 with SMTP id mu8mr3916613lbc.25.1384518432885; Fri, 15 Nov 2013 04:27:12 -0800 (PST) Received: by 10.112.67.12 with HTTP; Fri, 15 Nov 2013 04:27:12 -0800 (PST) In-Reply-To: References: Date: Fri, 15 Nov 2013 12:27:12 +0000 Message-ID: Subject: Re: decimal and builtin _sum function From: Robert Newson To: "user@couchdb.apache.org" Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable "I store the numbers as strings because I read this the proper way for decimals." You'll need a custom library to handle such strings. The article you read is just pointing out that a string will not be modified or interpreted in any way, which is the property you seek. But you'll need a multiprecision library that understands strings of that form to be able to process them. B. On 15 November 2013 12:19, Pedro Narciso Garc=EDa Revington wrote: > Yes, I know this is not couchdb stuff. What confused to me was to store > numbers as strings. > > > 2013/11/15 Robert Newson > >> Ah, sure. If you're using floating point to store (or compute on) >> money values you've committed a sin (I used to work in accounting >> software, this is the one thing you do not do, besides looking for a >> job not involving accounting software). >> >> We've had a few threads on number handling in the past and it gets >> complicated. Javascript really only has 64-bit floating point numbers >> in practice. Our JSON encoder/decoder will retain the precision of >> your input values but does not guarantee it will preserve the >> representation. >> >> If I were writing accounting software with CouchDB, I would be storing >> my money values as an object of three strings like >> {"amount":"200","dp":"2","currency":"USD"}, which represents $2. I >> would then perform all calculations in custom code, not being prepared >> to trust the various oddnesses of Javascript. >> >> Read https://issues.apache.org/jira/browse/COUCHDB-1410 for more fun. >> >> B. >> >> >> On 15 November 2013 11:55, Pedro Narciso Garc=EDa Revington >> wrote: >> > Yes, I'm dealing with money but also with micro decrements (cost per >> > impression on ads). >> > So my decrements are going to be like 0.000123. >> > I think what I'm going to do is to sum them before push them into couc= hdb >> > so I do not need to deal with decimals. >> > >> > >> > >> > 2013/11/15 Mike Marino >> > >> >> > To answer the original question, _sum can only sum numbers, it does >> >> > not understand numbers inside strings. >> >> > >> >> >> >> The way I understood the OP's question was that he had correctly, >> >> following the error message, converted to using numbers instead of >> >> strings, but then didn't understand the obtained result. >> >> >> >> >> >> >> sidenote: super cool talk by Bartek Szopka about floating point >> numbers >> >> in >> >> >> JavaScript (and other languages) held at JSConf.eu 2013 >> >> >> >> >> >> https://www.youtube.com/watch?v=3DMqHDDtVYJRI >> >> >> >> This is interesting, nice. I come from a background where numerical >> >> precision and memory layout is often a concern (e.g. physics >> >> simulations, hardware readout), but these types of things I think can >> >> be more easily forgotten when using higher level languages like >> >> javascript, python, etc. Imo it's still an essential understanding t= o >> >> have. >> >> >>