2

The following test fails:

@Test
public void testRound() throws Exception {
    double v = 0.015d;
    DecimalFormat format = new DecimalFormat("#.##", new DecimalFormatSymbols(Locale.US));
    format.setRoundingMode(RoundingMode.HALF_UP);
    assertEquals("0.02", format.format(v));
}

I see that there are resolved issues for Java 7 and Java 8, but it still doesn't work for me on "jdk1.8.0_144":

junit.framework.ComparisonFailure: null 
Expected :0.02
Actual   :0.01 
River
  • 8,585
  • 14
  • 54
  • 67
Liubov E.
  • 129
  • 1
  • 1
  • 9

1 Answers1

0

Use this:

DecimalFormat format = new DecimalFormat("#.###", new DecimalFormatSymbols(Locale.US));
Whitebear
  • 1,761
  • 2
  • 12
  • 22