为什么Couchbase在JSON文档中舍入数值? [英] Why Couchbase round numeric values in a json Document?

查看:43
本文介绍了为什么Couchbase在JSON文档中舍入数值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在记录Json文档时,有没有人注意到Couchbase在超过一定限制的情况下更改了属性的数值?

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

这里是一个例子.对于此测试,我使用通过couchbase Web界面进行的实时输入.

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

"inputValue"属性对应于在单击保存"按钮之前在"valueAfterSave"属性中输入的值.

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

属性"valueAfterSave"对应于保存后的值.

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

对于16位数字,这很好:

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

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

但是从17位开始,系统开始更改值:

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

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

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

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

只是出于好奇,只有40位数字

Just out of curiosity with 40 digits

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

此行为是在某处指定的吗?有没有办法改变它?通过String值有解决方案,但我承认我很好奇.

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.

我在Windows 7 Pro 32位平台上使用Couchbase Server 2.1.0.

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

推荐答案

Couhbase的技术推广员Tugdual Grall给了我答案.

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

这是由于JavaScript在显示此类值时的行为所致,如通过NodeJS进行的以下测试所证明的那样:

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

另一方面,Java API返回的值是正确的(在我们的示例中为12345678901234567890).只是控制台显示了这种差异.如果您通过Web管理控制台修改文档,则将保存修改后的值.

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.

拖拉谢谢你.

这篇关于为什么Couchbase在JSON文档中舍入数值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆