public class Slice {
public static void main (String [] args) {
double d = 987.123456d;
NumberFormat nf = NumberFormat.getInstance();
nf.setMaximumFractionDigits(4);
System.out.println(nf.format(d) + " ");
}
}
Output: 987.1235
Why does it exclude 4 and output isn’t 987.1234
Changing to nf.setMaximumFractionDigits(3); actually outputs 987.123
What you observed was caused by rounding not skipping.