const db = wx.cloud.database()
const $ = db.command.aggregate
db.collection('tota').aggregate()
.match({
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)
})
所有数字都是两位小数的,但是sum求和后得到11小位数
返回值
chenumsfzyue: 32985
chukouhuomoneysfzyue: 205213.28
chukouhuonumsfzyue: 1602
chukoukemoneysfzyue: 8892.39
chukoukenumsfzyue: 15521
chukoumoneysfzyue: 214105.66999999998
chukounumsfzyue: 17123
dzmoneysfzyue: 184854.78
dznumsfzyue: 7028
rukousfzyue: 15862
数据库中每条记录chukoumoneysfzyue字段的也都是2位小数点的。