收藏
回答

db.collection('xx').aggregate() 数据求和2位小数,变11位小数?

const db = wx.cloud.database()
            const $ = db.command.aggregate
            db.collection('tota').aggregate()
            .match({                        
               //gscttime : datasymd, 
               gscttime: db.RegExp({  //正则表达式
                regexp: '.*' + datasym,
                options: 'i',
                }),
                gsdanweiname:app.globalData.danweiname,
            })
           .group({
            _id: '$gsdanweiname',
            rukousfzyue: $.sum('$rukou'),
            chukouhuonumsfzyue: $.sum('$chukouhuonum'),
            chukouhuomoneysfzyue: $.sum('$chukouhuomoney'),
            chukoukenumsfzyue: $.sum('$chukoukenum'),
            chukoukemoneysfzyue: $.sum('$chukoukemoney'),
            chukounumsfzyue: $.sum('$chukounum'),
            chukoumoneysfzyue: $.sum('$chukoumoney'),
            chenumsfzyue: $.sum('$chenum'),
            dznumsfzyue: $.sum('$dznum'),
            dzmoneysfzyue: $.sum('$dzmoney'),
            })
           .limit(3000)
           .end()
           .then(res => {
            sfzyue = res;
             this.setData({
                sfzyue : sfzyue
             })
             console.log('返回值sfzyue', res)
            //that. addcaipurifenjun()
           })    
 所有数字都是两位小数的,但是sum求和后得到11小位数
返回值
chenumsfzyue: 32985
chukouhuomoneysfzyue: 205213.28            //像这个地方就是正常的。
chukouhuonumsfzyue: 1602
chukoukemoneysfzyue: 8892.39
chukoukenumsfzyue: 15521
chukoumoneysfzyue: 214105.66999999998       //这里为什么小数点后面会有那个位数,这个账务数据不能多1分,也不能少1分
chukounumsfzyue: 17123
dzmoneysfzyue: 184854.78
dznumsfzyue: 7028
rukousfzyue: 15862

数据库中每条记录chukoumoneysfzyue字段的也都是2位小数点的。
回答关注问题邀请回答
收藏
登录 后发表内容