保留小数点后几位的三种方法
var PI = 1213.141592653; // 常量大写 console.log(PI.toFixed(2)); console.log(parseInt(PI * 100) / 100); var str = PI + ""; // 因为数字没法进行字符操作 先转换 console.log(str.substr(0, str.indexOf(".") + 3));
var PI = 1213.141592653; // 常量大写 console.log(PI.toFixed(2)); console.log(parseInt(PI * 100) / 100); var str = PI + ""; // 因为数字没法进行字符操作 先转换 console.log(str.substr(0, str.indexOf(".") + 3));