incubator-couchdb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Elisiano Petrini <>
Subject Re: Decimal values in JSON
Date Tue, 16 Apr 2013 12:17:56 GMT
Hi Sander,
   there has been an extended discussion on this list a couple of months
ago about float numbers and their representation.

Have a look at
3Ckfvbob$c6p$ and follow the thread from there (sorry
I was unable to find a better view/link for that), it might answer some
of your questions.

Best Regards,
   Elisiano Petrini

On Tue, 2013-04-16 at 13:34 +0200, Sander Dijkhuis wrote:
> Hi,
> I’m 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’t 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 ‘doc’ variable that’s
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’s output?
> Sander
> [1]

View raw message