Based on this stackoverflow post, I would expect the following to print out 0.59 and not 0.60.
import java.math.RoundingMode;
import java.text.DecimalFormat;
public class Test {
public static void main(String[] args) {
double toFormat = 0.6;
DecimalFormat formatter = new DecimalFormat("########0.00");
formatter.setRoundingMode(RoundingMode.DOWN);
System.out.println(formatter.format(toFormat)); // 0.60
}
}
The closest floating point representation of 0.60 is 0.59999999999999997779553950749686919152736663818359375, which is below 0.6. With DecimalFormat set to RoundingMode.DOWN in Java 8, why isn't this rounded down to 0.59?