Quantcast
Viewing all articles
Browse latest Browse all 6

Difference between double and Double in comparison

I know that Double is a a wrapper class, and it wraps double number. Today, I have seen another main difference :

double a = 1.0;double b = 1.0;Double c = 1.0;Double d = 1.0;System.out.println(a == b);  // trueSystem.out.println(c == d);  // false

So strange with me !!!

So, if we use Double, each time, we must do something like this :

private static final double delta = 0.0001;System.out.println(Math.abs(c-d) < delta); 

I cannot explain why Double make directly comparison wrong. Please explain for me.


Viewing all articles
Browse latest Browse all 6

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>