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 D4716F610 for ; Tue, 16 Apr 2013 11:35:20 +0000 (UTC) Received: (qmail 71426 invoked by uid 500); 16 Apr 2013 11:35:19 -0000 Delivered-To: apmail-couchdb-user-archive@couchdb.apache.org Received: (qmail 71093 invoked by uid 500); 16 Apr 2013 11:35:19 -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 71068 invoked by uid 99); 16 Apr 2013 11:35:18 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 16 Apr 2013 11:35:18 +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 mail@sanderdijkhuis.nl designates 209.85.217.173 as permitted sender) Received: from [209.85.217.173] (HELO mail-lb0-f173.google.com) (209.85.217.173) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 16 Apr 2013 11:35:12 +0000 Received: by mail-lb0-f173.google.com with SMTP id w20so446597lbh.32 for ; Tue, 16 Apr 2013 04:34:51 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-received:from:content-type:content-transfer-encoding:subject :message-id:date:to:mime-version:x-mailer:x-gm-message-state; bh=3z7YuXz/K71T17k1DaiSjX/Q2HmN08GxOamVNrhvNYQ=; b=ijm3mCVG0pCr1g1H08UuQdP+JlO7jbikd1cweQ4oNUZavOCJKSGJE34w+FrY6wHNtP Puv8QNYgNFGW6/eoAA90qTMrDgOyTabcODyNqbiToIwOEroKgexlrfE1svSdn/SZrKz4 P8jddAJCAv2DM4KeSFq510RGFeNvpQ8HtgVarPF8w6CDnq4eGcXAiH2HeBdMVo0irm1l RcJ9b58HVZLUtATaQ8qCyD5O2a86ZNXPZnC74gCWt4fEcOAD8y1Z4/CcyLlSj6R88UtY fTU8Hsb+I9NPjNJZQGA91gF031+2+t6XeoE5jOye8PAOnPBmvNfltc2q4mC4/jVx1oV1 4lPA== X-Received: by 10.112.139.102 with SMTP id qx6mr1147917lbb.99.1366112091282; Tue, 16 Apr 2013 04:34:51 -0700 (PDT) Received: from [10.22.52.13] ([194.29.118.163]) by mx.google.com with ESMTPS id rn10sm746945lbb.16.2013.04.16.04.34.49 (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 16 Apr 2013 04:34:50 -0700 (PDT) From: Sander Dijkhuis Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: quoted-printable Subject: Decimal values in JSON Message-Id: Date: Tue, 16 Apr 2013 13:34:48 +0200 To: user@couchdb.apache.org Mime-Version: 1.0 (Mac OS X Mail 6.3 \(1503\)) X-Mailer: Apple Mail (2.1503) X-Gm-Message-State: ALoCoQkCh+oM0jcuNOdq3Bc6i3vHpL/pqxVD0fl3ci9gVGdXbm9NdKTkFK3VbFZxy59MaibPvd9Z X-Virus-Checked: Checked by ClamAV on apache.org Hi, I=92m working on a CouchDB design doc that provides a Cosm-like API to = work with sensor measurements. I know that the CouchDB guide recommends = using strings to represent decimal values in JSON[1], but was curious to = try using the { "field": 4.2 } format as it gives a cleaner API. I = figured that as long as data is sent in the right format, CouchDB might = handle it well as JSON doesn=92t specify that decimals should be = considered as floats. So far my update handler measurement(doc, req) seems to process the data = correctly. The raw req.body input string contains the value represented = with { "field": 4.2 }, and after JSON-parsing the input (but not = changing the decimal field), the =91doc=92 variable that=92s sent back = to CouchDB still seems to contain the field as 4.2, at least as shown by = log(JSON.stringify(doc)). Only when I request the _changes feed, any map/reduce view or a = particular doc, the value comes out of CouchDB as { "field": = 4.200000000002 } in JSON. I wonder if this is a bug in CouchDB? Or did = the log(doc) already deceive me and use different JSON serialisation = than CouchDB uses when processing the update handler=92s output? Sander [1] http://guide.couchdb.org/draft/json.html#numbers