couchdb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Mark Hahn <m...@reevuit.com>
Subject Re: decimal and builtin _sum function
Date Fri, 15 Nov 2013 18:01:18 GMT
> There are many definitions of rounding.

Don't you get to choose which one to use?  Nothing is forced on you.


On Fri, Nov 15, 2013 at 9:57 AM, Jens Alfke <jens@couchbase.com> wrote:

>
> On Nov 15, 2013, at 9:31 AM, Mark Hahn <mark@reevuit.com> wrote:
>
> >> When you store and then retrieve the number 0.3, you'd really like to
> know
> >> that it will come back in the same form. Without knowing about the
> innards
> >> of CouchDb and how it processes JSON, that's hard to guarantee.
> >
> > A JS number is the same whether going through JSON or not.  There is no
> > possible change.
>
> That’s not true. JavaScript usually stores numbers as 64-bit IEEE floating
> point. JSON is a _textual_ format, so converting numbers to JSON involves
> writing them as strings, which is a lossy conversion. It’s especially lossy
> if you sacrifice a bit of accuracy to display decimals in a more
> human-friendly way, i.e. writing “0.3” instead of “0.299999999998”, which I
> think most JSON encoders do because otherwise users complain about their
> numbers coming out “wrong” or at least “too long”.
>
> —Jens (who has written a few JSON encoders)

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message