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 BA21C1017B for ; Fri, 15 Nov 2013 10:46:44 +0000 (UTC) Received: (qmail 80438 invoked by uid 500); 15 Nov 2013 10:46:42 -0000 Delivered-To: apmail-couchdb-user-archive@couchdb.apache.org Received: (qmail 80375 invoked by uid 500); 15 Nov 2013 10:46: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 80364 invoked by uid 99); 15 Nov 2013 10:46:39 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 15 Nov 2013 10:46:39 +0000 X-ASF-Spam-Status: No, hits=-0.7 required=5.0 tests=RCVD_IN_DNSWL_LOW,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (nike.apache.org: domain of robert.newson@gmail.com designates 209.85.215.54 as permitted sender) Received: from [209.85.215.54] (HELO mail-la0-f54.google.com) (209.85.215.54) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 15 Nov 2013 10:46:34 +0000 Received: by mail-la0-f54.google.com with SMTP id ev20so2563514lab.41 for ; Fri, 15 Nov 2013 02:46:13 -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:content-transfer-encoding; bh=4RM5/qai2ioiH3IrJBxYwZRDdqXlcC+0Vs9EHFONzCE=; b=o47WyUS/7ammu4s03x4FP0hOpPttyak1gyECi9E3ye5LJk0e18zYabaZdI54eQj1hg dFoAXmuyJ1dVcqDJImik7ThEvtCrV2ZdPGdZN3r9Gmepe0FPrDRj8NzVHdLj7jQx0bKm ecFrp47vnTeZHBSltsqJMe2j9IBBYksSvfehRP46UeDSvQEwDsKsVTBAZiHuQKnPt2EW OpVXbAhUuPGrVEnitdBpU9moaXkwcVB5S6m73eP5dYvcL9xoaB8PicSjaonRlBxVCM/r /BJ9kAJKTCnqt+uiDnTSSwnz3ZaZFlie9d35ZjQpRlMGDZ5Gs5cTPBWJPc0rijmaB+ei IANg== MIME-Version: 1.0 X-Received: by 10.112.144.105 with SMTP id sl9mr934513lbb.37.1384512373652; Fri, 15 Nov 2013 02:46:13 -0800 (PST) Received: by 10.112.67.12 with HTTP; Fri, 15 Nov 2013 02:46:13 -0800 (PST) In-Reply-To: References: Date: Fri, 15 Nov 2013 10:46:13 +0000 Message-ID: Subject: Re: decimal and builtin _sum function From: Robert Newson To: "user@couchdb.apache.org" , Andreas Wenk Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Virus-Checked: Checked by ClamAV on apache.org To answer the original question, _sum can only sum numbers, it does not understand numbers inside strings. On 15 November 2013 10:27, Andy Wenk wrote: > sidenote: super cool talk by Bartek Szopka about floating point numbers i= n > JavaScript (and other languages) held at JSConf.eu 2013 > > https://www.youtube.com/watch?v=3DMqHDDtVYJRI > > > On 15 November 2013 11:00, Mike Marino wrote: > >> Hi Pedro, >> >> On Fri, Nov 15, 2013 at 10:29 AM, Pedro Narciso Garc=EDa Revington >> wrote: >> > Hi, >> > >> > I want to sum decimals with the builtin _sum function. >> > My documents look like >> > { >> > "_id": "7a2c5e50dfeb1341d02aa27c7a05f629", >> > "_rev": "4-482ff2f6b6e5c2aa079e3e4114d02093", >> > "type": "payment", >> > "amount": "0.2" >> > } >> > I store the numbers as strings because I read this the proper way for >> > decimals. >> >> I would echo Stefan's suggestion in this case since you're dealing >> with adding "money" numbers. Otherwise, you have to deal with normal >> numerical rounding issues when performing operations on floats. >> >> > >> > If I try to sum them with the builtin _sum I get the following error >> > "builtin _sum function requires map values to be numbers" >> > >> > I removed the quotes from the numbers. Now I can sum them but 0.2 + 0.= 1 >> > equals to 2.99999999 >> >> Was this a typo? Did you mean 0.2999999 ? >> >> Cheers, >> Mike >> > > > > -- > Andy Wenk > Hamburg - Germany > RockIt! > > http://www.couchdb-buch.de > http://www.pg-praxisbuch.de > > GPG fingerprint: C044 8322 9E12 1483 4FEC 9452 B65D 6BE3 9ED3 9588