// 使用toFixed()方法
const num = 3.1012;
const result = num.toFixed(2);
console.log(result);
// 使用parseFloat()和toFixed()方法结合
const num = 3.1012;
const result = parseFloat(num.toFixed(2));
console.log(result);
// 使用Math.round()方法
const num = 3.1012;
const result = Math.round(num * 100) / 100;
console.log(result);
// 使用正则表达式
const num = 3.1012;
const result = num.toString().match(/^\d+(?:\.\d{0,2})?/)[0];
console.log(parseFloat(result));