Get the App
SLTechnology News&Howtos  ›  Development  › 

How does js judge whether the decimals are equal?

Shulou Source: shulou.com Published: 2022-06-01 06:11:42 10月02日 Update

This article mainly introduces js how to judge whether the decimals are equal, the article is very detailed, has a certain reference value, interested friends must read it!

Judge whether the decimals are equal or not

Function epsEqu {return Math.abs (x-y) < Math.pow (2,-53);} / / example 0.1 + 0.2 = 0.3 / / falseepsEuq (0.1 + 0.2,0.3) / / true copy the code

The user enters decimal numbers and the computer saves binary numbers. So there will be some deviation in the calculation results, so we should not directly compare the non-integers, but take the upper limit and take the error into account. Such an upper limit is called machine epsilon, and the standard epsilon value for double precision is 2 ^-53 (Math.pow (2,-53)).

The above is all the contents of the article "how to judge whether decimals are equal by js". Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!

Tags: Decimal upper limit content article binary code value deviation interest decimal boy buddy number integer more standard user knowledge precision result Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Redmi Shulou Technology Huawei NVidia OPPO Reno