码迷,mamicode.com
首页 > 其他好文 > 详细

小数相加减 精度问题

时间:2018-03-21 16:31:18      阅读:170      评论:0      收藏:0      [点我收藏+]

标签:com   .com   技术   精度   body   ==   return   art   mon   

 

 

 

技术分享图片

 

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;
            }

 

小数相加减 精度问题

标签:com   .com   技术   精度   body   ==   return   art   mon   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!