var a=3.1415926; a = a.toFixed(2);//保留2位但结果为一个String类型 a = parseFloat(a);//将结果转换会float //用一步的话如下 a = parseFloat(a.toFixed(2));