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