To my understanding, with half-even rounding, if the number that you are rounding on is equidistant between its neighbors (for example 4.5 if you are rounding on one after the decimal), you round the preceding number to the nearest even number.
For example, if you are rounding to 0 digits after the decimal 1.5, 3.5, 5.5, 7.5, and 9.5 will all be rounded up to 2, 4, 6, 8, and 10 respectively. This all works well and fine in netbeans, but I am running into problems when I round to 1 place after the decimal.
package foo;
import java.text.NumberFormat;
public class Foo {
public static void main(String[] args) {
NumberFormat formatter = NumberFormat.getNumberInstance();
formatter.setMaximumFractionDigits(1);
System.out.print(formatter.format(4.45));
}
}
run:
4.5
BUILD SUCCESSFUL (total time: 0 seconds)
I would think that this would round to 4.4
Additionally, if I use 4.55 for input into format, 4.5 is output where I expect 4.6 Is there an error with java or with my understanding?