我有一個舍入數字的問題。JavaScript圓形錯誤
x = 0.175;
console.log(x.toFixed(2));
// RESULT: 0.17
x = 1.175;
console.log(x.toFixed(2));
// RESULT: 1.18
x = 2.175;
console.log(x.toFixed(2));
// RESULT: 2.17
爲什麼(X!= 1)0.175不四捨五入到十.18?
我總是得到'* .18'的東西。 –
嘗試'toFixed(20)',你會明白爲什麼。 – georg
JavaScript糟糕的數字系統 – Mahi