优化前端浮点数计算

master
chenzhi 5 years ago
parent 6baba8db28
commit 864e8d693a

@ -447,6 +447,12 @@
callback(data) callback(data)
} }
}) })
},
floatAdd(a,b){
return Math.round(a*100+b*100)/100;
},
floatCut(a,b){
return Math.round(a*100-b*100)/100;
} }
} }
//数据类 //数据类
@ -627,28 +633,31 @@
}else{ }else{
var ratio = td['second_ratio']/100; var ratio = td['second_ratio']/100;
} }
DATAOBJ.statement_count['sum_money'] -= td['sum_money']; DATAOBJ.statement_count['sum_money'] = PUBLIC.floatCut(DATAOBJ.statement_count['sum_money'],td['sum_money']);
td['sum_money'] = Math.floor((td['pay_amount']*(100-td['promote_ratio'])/100*ratio*(100-td['fax_ratio'])/100)* 100) / 100 ; td['sum_money'] = Math.round((td['pay_amount']*(100-td['promote_ratio'])/100*ratio*(100-td['fax_ratio'])/100)* 100) / 100 ;
DATAOBJ.statement_count['sum_money']+=(td['sum_money']-0);
DATAOBJ.statement_count['sum_money']=PUBLIC.floatAdd(DATAOBJ.statement_count['sum_money'],td['sum_money']);
}else{ }else{
DATAOBJ.fine = Math.floor(DATAOBJ.fine * 100) / 100 ; DATAOBJ.fine = Math.round(DATAOBJ.fine * 100) / 100 ;
if(!CHECK.money.test(val)){
layer.msg('罚款金额格式错误');
$(this).val(DATAOBJ.fine);
return false;
}
if(val > DATAOBJ.statement_count['sum_money']){ if(val > DATAOBJ.statement_count['sum_money']){
layer.msg('罚款金额过大,总计不允许为负数'); layer.msg('罚款金额过大,总计不允许为负数');
$(this).val(DATAOBJ.fine); $(this).val(DATAOBJ.fine);
return false; return false;
} }
DATAOBJ.statement_count['sum_money'] = (DATAOBJ.statement_count['sum_money'] -0+DATAOBJ.fine); DATAOBJ.statement_count['sum_money'] =PUBLIC.floatAdd(DATAOBJ.statement_count['sum_money'],DATAOBJ.fine);
DATAOBJ.statement_count['pay_amount'] = (DATAOBJ.statement_count['pay_amount'] -0+DATAOBJ.fine); DATAOBJ.statement_count['pay_amount'] = PUBLIC.floatAdd(DATAOBJ.statement_count['pay_amount'],DATAOBJ.fine);
eval(str); eval(str);
DATAOBJ.statement_count['sum_money'] = DATAOBJ.statement_count['sum_money']-DATAOBJ.fine; DATAOBJ.statement_count['sum_money'] =PUBLIC.floatCut(DATAOBJ.statement_count['sum_money'],DATAOBJ.fine);
DATAOBJ.statement_count['pay_amount'] = DATAOBJ.statement_count['pay_amount']-DATAOBJ.fine; DATAOBJ.statement_count['pay_amount'] = PUBLIC.floatCut(DATAOBJ.statement_count['pay_amount'],DATAOBJ.fine);
} }
DATAOBJ.statement_count['pay_amount'] = Math.floor(DATAOBJ.statement_count['pay_amount'] * 100) / 100 ;
DATAOBJ.statement_count['sum_money'] = Math.floor(DATAOBJ.statement_count['sum_money'] * 100) / 100;
TPLSHOW.showStatementList(true); TPLSHOW.showStatementList(true);
}) })
}, },

Loading…
Cancel
Save