Comparison with bigdecimal

Правка en2, от rahul_1234, 2015-07-21 17:52:36

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.

Теги comparison, bigdecimal

История

 
 
 
 
Правки
 
 
  Rev. Язык Кто Когда Δ Комментарий
en2 Английский rahul_1234 2015-07-21 17:52:36 12
en1 Английский rahul_1234 2015-07-21 17:51:53 370 Initial revision (published)