rahul_1234's blog

By rahul_1234, history, 9 years ago, In English

In C++, for comparing doubles we do:

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

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.

  • Vote: I like it
  • -8
  • Vote: I do not like it