[英]Floating point precision rounding up or down
Due to conversion between binary and decimal numbers we often see precision errors in JS.由于二进制数和十进制数之间的转换,我们经常会在 JS 中看到精度错误。
eg.: 137.80 * 100 = 13780.000000000002
例如:
137.80 * 100 = 13780.000000000002
Although, is is technically possible that JS will return similar error but with negative precision?虽然,从技术上讲,JS 是否有可能返回类似的错误但精度为负?
eg.: 137.80 * 100 = 13779.999999999998
例如:
137.80 * 100 = 13779.999999999998
Absolutely.绝对地。 For instance,
0.3 / 10000
is 0.000029999999999999997
because 0.3
can't quite be represented, and the closest representation is just slightly lower that the actual value 0.3
.例如,
0.3 / 10000
是0.000029999999999999997
因为0.3
不能完全表示,最接近的表示只是略低于实际值0.3
。 We can see that manifest in the output if we push the limits with the division.如果我们通过除法突破极限,我们可以在 output 中看到该清单。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.