How to compare two double values in Java?

后端 未结 7 1354
滥情空心
滥情空心 2020-11-22 13:10

A simple comparison of two double values in Java creates some problems. Let\'s consider the following simple code snippet in Java.

package doublecomparision;         


        
相关标签:
7条回答
  • 2020-11-22 14:06

    Just use Double.compare() method to compare double values.
    Double.compare((d1,d2) == 0)

    double d1 = 0.0;
    double d2 = 0.0;
    
    System.out.println(Double.compare((d1,d2) == 0))  // true
    
    0 讨论(0)
提交回复
热议问题