1

鉴于此代码:

const value = 1;
Math.sin(2 * Math.PI * value).toFixed(5);

"-0.00000"当之前的值.toFixed(5)是时,为什么会返回-2.4492935982947064e-16

4

3 回答 3

4

该数字采用科学计数法。

e-16 表示数字左侧有 16 个 0。

-2.4492935982947064e-16

是真的

-0.00000000000000024492935982947064

当你运行 toFixed(5) 时,你会得到 5 个小数位,它们都是 0。

于 2019-06-05T08:47:09.100 回答
0

你提供的数字-2.4492935982947064e-16是科学计数法。-2.4492935982947064 × 10^-16该数字将等于-0.00000000000000024492935982947064扩展后的数字。

于 2019-06-05T08:46:05.313 回答
0

-2.4492935982947064e-16-2.4492935982947064 * Math.pow(10,-16),所以小数点后 5 位不足以看到与 0 不同的东西

const value = 1;
let result = Math.sin(2 * Math.PI * value);
console.log(result)
console.log(result.toFixed(20))
console.log(result.toFixed(5))

于 2019-06-05T08:47:38.703 回答