Comparison with double

Revision en1, by rahul_1234, 2015-07-21 17:51:53

In C++, for comparing doubles we do:

bool AreSame(double a, double b) { return fabs(a — b) < epsilon; } // epsilon : 0.000000001

However in java to compare Bigdecimal properly would this suffice:

if(r.compareTo(BigDecimal.ZERO) == 0) { System.out.print("Yes"); }

Or we have to do something else. Can somebody elaborate on this.

Tags comparison, bigdecimal

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en2 English rahul_1234 2015-07-21 17:52:36 12
en1 English rahul_1234 2015-07-21 17:51:53 370 Initial revision (published)