item代表的是我們當前條數(shù)據(jù)
item.amount = item.amount.replace(/[^\d.]/g,""); // 清除“數(shù)字”和“.”以外的字符
item.amount = item.amount.replace(/\.{2,}/g,"."); // 只保留第一個. 清除多余的
item.amount = item.amount.replace(".","$#$").replace(/\./g,"").replace("$#$",".");
item.amount = item.amount.replace(/^(\-)*(\d+)\.(\d\d).*$/,'$1$2.$3'); // 只能輸入兩個小數(shù)
if(item.amount.indexOf(".") < 0 && item.amount != ""){ // 以上已經(jīng)過濾,此處控制的是如果沒有小數(shù)點殴蹄,首位不能為類似于 01韭脊、02的金額
? ? item.amount = parseFloat(item.amount);
}
if(item.amount && item.amount.indexOf(".") > -1 && item.amount === '0.00'){ // 排除0.00
? ? item.amount = parseFloat(item.amount).toFixed(1)
}