I have this:
double a = ...;
double b = ...;
if (a < b) {
....
} else
....
But I cannot use this approach with floating points (double) because, for example:
double a = 5 - 4.9 = 0.999999964;
double b = 0.1;
a < b = true // when it should be false
I was thinking in two possible solutions
The first one using multiplying by a certain number, casting to int and rounding:
(int) Math.round(a * 10_000) < (int) Math.round(b * 10_000);
Or using an epsilon in this way:
double decimaPrecision = 0.00001; double max = Math.max(a, b); double min = Math.min(a, b); return Math.abs(a/ b) > (1.0 + decimaPrecision);
What approach shall I use? Do you knowa better way of checking this? Do you know any 3pp which does these kind of stuffs?