Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How does js judge whether the decimals are equal?

2025-03-26 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

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!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report