计算时用parseFloat,计算完后转换成Number对象

var ytje = parseFloat("0.03");
var handlecharge = parseFloat("0.01");
ytje = ytje-handlecharge;
ytje = new Number(ytje).toFixed(2);
console.log(ytje);

如果不转换成Number对象,则会存在丢失精度问题,如下图片:

js 计算丢失精度问题-LMLPHP

05-06 09:44