Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
bgColor#FFCCCC
int i = 1;
String s = Double.valueOf (i / 1000.0).toString(); // s contains 0.0010
if(s.equals("0.001")) { // Fails
  // Do something
}

...

Code Block
bgColor#ccccff
int i = 1;
BigDecimal d = new BigDecimal(Double.valueOf (i / 1000.0).toString()).stripTrailingZeros();
if(s.equals(d.compareTo(new BigDecimal("0.001")) == 0) { // Passes
  // Do something
}

...