On Nov 15, 2013, at 9:31 AM, Mark Hahn <[email protected]> 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)

Reply via email to