NumberFormat nf = NumberFormat.getInstance(); nf.setMaximumFractionDigits(4); nf.setMinimumFractionDigits(2); String a = nf.format(3.1415926); String b = nf.format(2); Which statement is true about the result?
-
The value of b is 2
-
The value of b is 2.00
-
The value of a is 3.141
-
The value of a is 3.1415
B
Correct answer
Explanation
This is the same question as 154036. NumberFormat.setMinimumFractionDigits(2) ensures at least 2 decimal places. Integer 2 becomes 2.00. The value 3.1415926 gets rounded to 4 decimal places (maximum), giving 3.1415.