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 E7889103CA for ; Fri, 15 Nov 2013 12:19:43 +0000 (UTC) Received: (qmail 20370 invoked by uid 500); 15 Nov 2013 12:19:42 -0000 Delivered-To: apmail-couchdb-user-archive@couchdb.apache.org Received: (qmail 20045 invoked by uid 500); 15 Nov 2013 12:19:41 -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 20037 invoked by uid 99); 15 Nov 2013 12:19:40 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 15 Nov 2013 12:19:40 +0000 X-ASF-Spam-Status: No, hits=1.5 required=5.0 tests=HTML_MESSAGE,RCVD_IN_DNSWL_LOW,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: domain of p.revington@gmail.com designates 209.85.219.48 as permitted sender) Received: from [209.85.219.48] (HELO mail-oa0-f48.google.com) (209.85.219.48) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 15 Nov 2013 12:19:36 +0000 Received: by mail-oa0-f48.google.com with SMTP id n16so3832849oag.35 for ; Fri, 15 Nov 2013 04:19:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; bh=znAnxonoPmNEl4/ilcs6BP75PyBX28wv6U/ldca81Jo=; b=ihQcWA99VXI+HgFSLO3CRpNXA8Y/tqlDW+pPLubf5Fo+6qbWNPxZDTV4y7FBjP2Srn PPVES+CltJLXd0lwBVwDIya400pHO78HIzIXbr2UOayJsbhoyVQtajcvqZEMi8QV/q6w TxXiu7ycPYlKMzVxI0SjpTwtcZovT5kHomJZ2SVpAs0tWF/wya8xxMd7/Dp/8ko1/oJ9 Zm1UfRBPIov8A3NWvmkbkG/sSfQAG3mIxfhF2ORe9IllPqZVKB0xna5D9vrLxbR506bF ppVas904T27UllSTTPjOf6nmGCJ4YBrpn+fGTpr4uwfMLBB21wNA82wLST2q5HnG5gXG N7Hw== MIME-Version: 1.0 X-Received: by 10.182.233.137 with SMTP id tw9mr284676obc.87.1384517955492; Fri, 15 Nov 2013 04:19:15 -0800 (PST) Received: by 10.182.36.71 with HTTP; Fri, 15 Nov 2013 04:19:15 -0800 (PST) In-Reply-To: References: Date: Fri, 15 Nov 2013 13:19:15 +0100 Message-ID: Subject: Re: decimal and builtin _sum function From: =?UTF-8?Q?Pedro_Narciso_Garc=C3=ADa_Revington?= To: user@couchdb.apache.org Content-Type: multipart/alternative; boundary=001a11c1c556ec20e404eb36348e X-Virus-Checked: Checked by ClamAV on apache.org --001a11c1c556ec20e404eb36348e Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable 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=C3=ADa 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 couch= db > > 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 to > >> have. > >> > --001a11c1c556ec20e404eb36348e--