Math.round(x) 四舍五入,如Math.round(0.70),结果为1;Math.round(0.39),结果为0;
Math.floor(x) 向下舍入,如Math.floor(0.70)与Math.floor(0.39),结果均为0;
Math.ceil(x)向上舍入,如Math.ceil(0.70)与Math.ceil(0. 39),结果均为1;
parseInt(x)丢弃小数部分,保留整数部分,parseInt(3.14),结果为3。
Math.floor():
_.each(cart_items,function(key){ var promotions_barcode=promotions_items[0].barcodes; if(promotions_barcode.indexOf(key.barcode)!=-1){ key.promotions_count=Math.floor(key.count/3);//获取3的整数倍,向下取整 } else{ key.promotions_count=0; } });
parseInt():
function getResult(num){ return parseInt(num); }
Math.ceil():
function getResult(num,n){ return Math.ceil(num); }