// pages/shopping/shopping.js
Page({
/**
* 页面的初始数据
*/
data: {
products: [{
title:'普洱茶礼盒装1',
size:'规格:500g 礼盒装',
rmb:300.022,
nub:1
},{
title:'普洱茶礼盒装2',
size:'规格:400g 礼盒装',
rmb:400.00,
nub:1
}],
total: 0
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
this.total();
},
total:function(e){
var total = 0;
for(let i in this.data.products){
total+= (this.data.products[i].rmb*this.data.products[i].nub);
console.log(total);
};
this.setData({
products: this.data.products,
total:total
});
}
})
js精度问题 了解一下
电脑二进制计算,精度不够,建议保留两位小数,