What's wrong with using == to compare floats in Java?

后端 未结 21 1746
你的背包
你的背包 2020-11-22 01:00

According to this java.sun page == is the equality comparison operator for floating point numbers in Java.

However, when I type this code:



        
21条回答
  •  南笙
    南笙 (楼主)
    2020-11-22 01:35

    Here is a very long (but hopefully useful) discussion about this and many other floating point issues you may encounter: What Every Computer Scientist Should Know About Floating-Point Arithmetic

提交回复
热议问题