JS保留两位小数只舍不进(简化写法) Posted on 2020-08-17 16:30:00 In JavaScript 123456const DECIMAL_PREFIX = 1;var x = 144.4599999999;var y = parseFloat(JSON.stringify(x).substring(0, JSON.stringify(x).lastIndexOf('.') + DECIMAL_PREFIX + 2)); // 2 = 保留小数点后的位数console.log(y);// 输出:144.45 Buy me a coffee Donate Alipay