首页 > 其他 > 详细

小数相加减 精度问题

时间:2018-03-21 15:58:12      阅读:206      评论:0      收藏:0      [点我收藏+]

 

 

 

技术分享图片

 

changeCartNum () {
                this.shopCart.num=0;
                this.shopCart.totalMoney=0;
                for(var i=0; i<this.shopCart.items.length;i++){
                    this.shopCart.num+=this.shopCart.items[i].sku.num;
                    this.shopCart.totalMoney+=this.shopCart.items[i].sku.num*this.shopCart.items[i].sku.price;
                }
                if(this.shopCart.num==0){
                    this.showCart= !this.showCart;
                }
                this.shopCart.totalMoney= this.getCurrentMoney(this.shopCart.totalMoney);
            },
            getCurrentMoney (money) {
                let money1 = money * 100;
                let intMoney1 = parseInt(money1);
                let diff = money1 - intMoney1;
                let decDiff = parseInt(diff * 10);
                if (decDiff > 5) {
                    intMoney1 += 1;
                }

                return intMoney1/100;
            }

 

小数相加减 精度问题

原文:https://www.cnblogs.com/MR-cui/p/8617423.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!