public void TestRounding() { double Roundingnumber = 2.55; double Roundingnumber1 = -2.55; // +2.55 results -2.55 results double result[] = { 3, -3, 2, -2, 3, -2, 2, -3, 3, -3, 3, -3, 3, -3 }; DecimalFormat pat = new DecimalFormat(); String s = ""; s = pat.toPattern(); logln("pattern = " + s); int mode; int i = 0; String message; String resultStr; for (mode = 0; mode < 7; mode++) { pat.setRoundingMode(mode); if (pat.getRoundingMode() != mode) { errln("SetRoundingMode or GetRoundingMode failed for mode=" + mode); } // for +2.55 with RoundingIncrement=1.0 pat.setRoundingIncrement(1.0); resultStr = pat.format(Roundingnumber); message = "round(" + (double) Roundingnumber + "," + mode + ",FALSE) with RoundingIncrement=1.0==>"; verify(message, resultStr, result[i++]); message = ""; resultStr = ""; // for -2.55 with RoundingIncrement=1.0 resultStr = pat.format(Roundingnumber1); message = "round(" + (double) Roundingnumber1 + "," + mode + ",FALSE) with RoundingIncrement=1.0==>"; verify(message, resultStr, result[i++]); message = ""; resultStr = ""; } }