Some numbers within Json get modified on save

When I try saving following document, the value gets modified to 12399999999999124.
{
“something”: 12399999999999123
}

This happens when creating a document through the console also, that is when I realized this post belongs in Couchbase Server topics, not Java sdk topics.

Some interesting notes on the numbers I tried:
12399999999999123 saved as 12399999999999124
12399999999999124 saved correctly as is
12399999999999125 saved as 12399999999999124
12399999999999126 saved correctly as is
99999999999999999 saved as 100000000000000000

I am using Couchbase server 2.5.

I did not find any known issue when searching for this. Has anyone seen this behavior before?
Thanks.

Yeah, JSON spec does not limit numbers in any way, but Javascript implementation treat them as Numbers: http://www.ecma-international.org/ecma-262/5.1/#sec-4.3.19

So preserving original number depends completely on which JSON parsers are you using with the data. Just make sure that you only use those which can properly convert to native types and back. (and do not use console, which likely use your browser’s javascript implementation).

Another point, which you cannot eliminate, is the view engine, which uses v8 javascript engine when interpreting your documents. So here you again will get them trimmed.

Maybe your application should serialize numbers to strings and use BigInteger(String val) to decode them back, if it is very sensitive.

Thanks for the reply. After I saw your reasoning, I was also able to find some useful discussions on the topic like this one: http://stackoverflow.com/questions/1379934/large-numbers-erroneously-rounded-in-javascript.