为什么尝试将 2.05 与 1.01 相加会返回此值?
console.log(2.05+1.01); // -> 3.0599999999999996?
使用 toFixed() 是唯一的方法吗?
console.log((2.05+1.01).toFixed(2))
我怎样才能避免这种行为,所以它不会让我在我的代码的内部计算中感到惊讶。
为什么尝试将 2.05 与 1.01 相加会返回此值?
console.log(2.05+1.01); // -> 3.0599999999999996?
使用 toFixed() 是唯一的方法吗?
console.log((2.05+1.01).toFixed(2))
我怎样才能避免这种行为,所以它不会让我在我的代码的内部计算中感到惊讶。