Why Couchbase round numeric values in a json Document?

感情迁移 提交于 2019-12-24 01:42:44

问题


Is there anyone who had noted that Couchbase changes the numerical value of a property, over a certain limit, when recording a Json document?

Here is an example. For this test, I use the live input via the couchbase web interface.

The property "inputValue" corresponds to the value entered in the property "valueAfterSave" before clicking the save button.

The property "valueAfterSave" corresponds to the value after the save.

To a number with 16 digits, it's good:

{
  "inputValue": "1234567890123456",
  "valueAfterSave": 1234567890123456
} 

But from 17 digits, the system begins to change the value:

{
  "inputValue": "12345678901234567",
  "valueAfterSave": 12345678901234568
}

or

{
  "inputValue": "12345678901234599",
  "valueAfterSave": 12345678901234600
}

or

{
  "inputValue": "12345678901234567890",
  "valueAfterSave": 12345678901234567000
}

Just out of curiosity with 40 digits

{
  "inputValue": "1234567890123456789012345678901234567890",
  "valueAfterSave": 1.234567890123457e+39
}

This behavior is specified somewhere? Is there a way to change it ?. There is the solution through String values ​​but I admit that I'm curious.

I use Couchbase Server 2.1.0 on Windows 7 Pro 32-bit platform.


回答1:


Tugdual Grall, technical evangelist at Couhbase, brought me the answer.

This is due to the behavior of JavaScript when displaying such values ​​as evidenced by the following test with NodeJS:

$ node
> console.log(12345678901234567890)
12345678901234567000

On the other hand, the value returned by the Java API is correct (12345678901234567890 in our example). It is just the console which shows this difference. If you modify the document, through the web administration console, it is the modified value which will be saved.

So be careful with the use of the administration Console when we handle this type of data.

Tug thank you.



来源:https://stackoverflow.com/questions/18532186/why-couchbase-round-numeric-values-in-a-json-document

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!