JS retains two decimal places and only rounds it up (simplified writing)

const 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

Guess you like

Origin blog.csdn.net/qq_35977139/article/details/108057804