- 小程序为什么计算 917.52 - 1000= -82.48000000000002?
小程序为什么计算 917.52 - 1000= -82.48000000000002? 其他的计算都没有问题,就这一个有问题, 如图所示,图中为console.log显示的结果 [图片] 数据是从数据库中读取的,源代码如下: [代码]var[代码] [代码]that = [代码][代码]this[代码][代码];[代码][代码] [代码][代码]wx.cloud.callFunction({[代码][代码] [代码][代码]name: [代码][代码]'getMoney'[代码][代码],[代码][代码] [代码][代码]data: {[代码][代码] [代码][代码]objThisId: that.data.thisId,[代码][代码] [代码][代码]},[代码][代码] [代码][代码]complete: [代码][代码]function[代码] [代码](res) {[代码][代码] [代码][代码]try[代码] [代码]{[代码][代码] [代码][代码]var[代码] [代码]objNub = res.result.data.length[代码][代码] [代码][代码]//获取数据量[代码][代码] [代码][代码]if[代码] [代码](objNub > 0) {[代码][代码] [代码][代码]//获取数据[代码][代码] [代码][代码]for[代码] [代码](let i = 0; i < objNub; i++) {[代码][代码] [代码][代码]if[代码] [代码](res.result.data[i].moneyBool == [代码][代码]"true"[代码][代码]) {[代码][代码] [代码][代码]objlbMoney = objlbMoney + parseFloat(res.result.data[i].money);[代码][代码] [代码][代码]objlbIncome = objlbIncome + parseFloat(res.result.data[i].money);[代码][代码] [代码][代码]console.log([代码][代码]"原余额:"[代码] [代码]+ objlbMoney)[代码][代码] [代码][代码]console.log([代码][代码]"原收入:"[代码] [代码]+ objlbIncome)[代码][代码] [代码][代码]console.log([代码][代码]"收入:"[代码] [代码]+parseFloat(res.result.data[i].money))[代码][代码] [代码][代码]console.log([代码][代码]"---------------"[代码][代码])[代码][代码] [代码][代码]}[代码][代码] [代码][代码]else[代码] [代码]if[代码] [代码](res.result.data[i].moneyBool == [代码][代码]"false"[代码][代码]) {[代码][代码] [代码][代码]objlbMoney = objlbMoney - parseFloat(res.result.data[i].money);[代码][代码] [代码][代码]objlbExpend = objlbExpend - parseFloat(res.result.data[i].money);[代码][代码] [代码][代码]console.log([代码][代码]"原余额:"[代码] [代码]+ objlbMoney)[代码][代码] [代码][代码]console.log([代码][代码]"原支出:"[代码] [代码]+ objlbExpend)[代码][代码] [代码][代码]console.log([代码][代码]"支出:"[代码] [代码]+parseFloat(res.result.data[i].money))[代码][代码] [代码][代码]console.log([代码][代码]"---------------"[代码][代码])[代码][代码] [代码][代码]}[代码][代码] [代码][代码]}[代码][代码] [代码][代码]}[代码][代码] [代码][代码]//查询错误[代码][代码] [代码][代码]else[代码] [代码]if[代码] [代码](objNub < 0) {[代码][代码] [代码][代码]console.log([代码][代码]'查询结果:'[代码] [代码]+ objNub)[代码][代码] [代码][代码]console.log([代码][代码]'系统错误!'[代码][代码])[代码][代码] [代码][代码]wx.switchTab({[代码][代码] [代码][代码]url: [代码][代码]'../index/home'[代码][代码],[代码][代码] [代码][代码]})[代码][代码] [代码][代码]}[代码][代码] [代码][代码]that.setData({[代码][代码] [代码][代码]lbMoney: objlbMoney,[代码][代码] [代码][代码]lbIncome: objlbIncome,[代码][代码] [代码][代码]lbExpend: objlbExpend,[代码][代码] [代码][代码]})[代码][代码] [代码][代码]} [代码][代码]catch[代码] [代码](e) {[代码][代码] [代码][代码]console.log([代码][代码]'调用云函数错误!'[代码][代码])[代码][代码] [代码][代码]wx.switchTab({[代码][代码] [代码][代码]url: [代码][代码]'../index/home'[代码][代码],[代码][代码] [代码][代码]})[代码][代码] [代码][代码]}[代码][代码] [代码][代码]}[代码][代码] [代码][代码]})[代码]
2019-10-22 - 使用云函数查询没有数据,但云端测试查询有数据,是什么情况?
[代码]// 云函数入口文件[代码][代码]const cloud = require([代码][代码]'wx-server-sdk'[代码][代码])[代码] [代码]cloud.init()[代码][代码]const db = cloud.database()[代码] [代码]// 云函数入口函数[代码][代码]exports.main = async (event, context) => {[代码][代码] [代码][代码]return[代码] [代码]db.collection([代码][代码]'BillDetails'[代码][代码]).where({[代码][代码] [代码][代码]userId: event.objThisId,[代码][代码] [代码][代码]dealYear:event.objDealYear,[代码][代码] [代码][代码]dealMonth:event.objDealMonth[代码][代码] [代码][代码]}).get()[代码][代码]}[代码]如上云函数语句,小程序查询时,结果为空。 [代码]var[代码] [代码]that = [代码][代码]this[代码][代码];[代码][代码] [代码][代码]wx.cloud.callFunction({[代码][代码] [代码][代码]name: [代码][代码]'getBill'[代码][代码],[代码][代码] [代码][代码]data: {[代码][代码] [代码][代码]objThisId: that.data.thisId,[代码][代码] [代码][代码]objDealYear: that.data.selYear,[代码][代码] [代码][代码]objDealMonth: that.data.showMonth,[代码][代码] [代码][代码]},[代码][代码] [代码][代码]complete: [代码][代码]function[代码] [代码](res) {[代码][代码] [代码][代码]console.log(that.data.thisId)[代码][代码] [代码][代码]console.log(that.data.selYear)[代码][代码] [代码][代码]console.log(that.data.showMonth)[代码][代码] [代码][代码]var[代码] [代码]objNub = res.result.data.length[代码][代码] [代码][代码]//获取数据量[代码][代码] [代码][代码]if[代码] [代码](objNub > 0) {[代码] [代码] [代码][代码]console.log([代码][代码]"................"[代码][代码])[代码][代码] [代码][代码]console.log(res.result.data[1])[代码][代码] [代码][代码]console.log(res.result.data.length)[代码][代码] [代码][代码]}[代码][代码] [代码][代码]//查询错误[代码][代码] [代码][代码]else[代码] [代码]if[代码] [代码](objNub < 0) {[代码][代码] [代码][代码]console.log([代码][代码]'查询结果:'[代码] [代码]+ objNub)[代码][代码] [代码][代码]console.log([代码][代码]'系统错误!'[代码][代码])[代码][代码] [代码][代码]}[代码][代码] [代码][代码]//查询[代码][代码] [代码][代码]else[代码][代码]{[代码][代码] [代码][代码]console.log([代码][代码]'查询结果:'[代码] [代码]+ objNub)[代码][代码] [代码][代码]}[代码][代码] [代码][代码]}[代码][代码] [代码][代码]})[代码]日志显示: {"data":[],"errMsg":"collection.get:ok"} 已确认,输入的条件能查询到三条数据! 并且,数据库集合权限设置为:“所有用户可读,仅创建者可读写”! 并且,查询的是创建者自己的数据!
2019-09-29