Reputation: 335
I tried to multiply each of the double by 100 and then use Math. around() before doing Math.abs() < 0.00000001 but it doesn't work.
double A = Math.sqrt(3);
double B = Math.sqrt(5);
Boolean result = Math.abs(Math.round(A * 100.0)/100.0 - Math.round(B * 100.0)/100.0) < 0.00000001
Upvotes: 0
Views: 142
Reputation: 21455
Math.sqrt(3) rounded to two digits is 1.73, Math.sqrt(5) rounded to two digits is 2.24. How do you expect these two values to match?
Upvotes: 1