简体   繁体   English

Javascript 大数解析

[英]Javascript large Number parsing

I am using a Couchbase view to emit a few records.我正在使用 Couchbase 视图来发出一些记录。 Among those records, there is one record which is 19 digit long.在这些记录中,有一条记录长度为 19 位。 When Couchbase view (written in javascript) pulls those record, it rounds off the record into smaller one and loses precision.当 Couchbase 视图(用 javascript 编写)提取这些记录时,它会将记录四舍五入为较小的记录并失去精度。

-7092643922943239825 is actual number but when retrieved from below view: -7092643922943239825 是实际数字,但从下面的视图中检索时:

function(doc, meta) {
if (doc.docType == 'xyz') {
    if (doc.source) {
            if (doc.source != null) {
                emit([doc.valA, doc.valB,  loc], 1);
            }
    } 
}

The output I get is:我得到的 output 是:

[ **-7092643922943240000, 1523365218128317200**, "abc" ]

I was expecting:我期待:

"doc": {
  "valA": 1523365218128317302,
  "valB": -7092643922943239825
}

What am I doing wrong?我究竟做错了什么?

It seems like you have cross posted this question, please refer to a detailed discussion concerning your issue as posted to https://forums.couchbase.com/t/couchbase-view-rounds-off-the-long-value-in-emit/34370 (the link was previously referenced by dnault )似乎您已经交叉发布了这个问题,请参阅发布到https://forums.couchbase.com/t/couchbase-view-rounds-off-the-long-value-in-的有关您的问题的详细讨论emit/34370 (该链接之前由dnault引用)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM