計算時用parseFloat,計算完後轉換成Number對象spa
var ytje = parseFloat("0.03"); var handlecharge = parseFloat("0.01"); ytje = ytje-handlecharge; ytje = new Number(ytje).toFixed(2); console.log(ytje);
若是不轉換成Number對象,則會存在丟失精度問題,以下圖片:code