DecimalFormat rounding issue?

Viewed 91

Am I doing something terribly wrong or does DecimalFormat really have an issue with rounding?

DecimalFormat format = new DecimalFormat("#.####");
format.setRoundingMode(RoundingMode.HALF_UP); // .5 up, .4 down?
format.setDecimalFormatSymbols(DecimalFormatSymbols.getInstance(Locale.ENGLISH)); // . as decimal seperator

System.out.println(format.format(1.848751)); // 1.8488 -> thats correct
System.out.println(format.format(1.848750)); // 1.8487 -> that is not correct
System.out.println(format.format(1.84875)); // 1.8487 -> that is not correct
0 Answers
Related