Multiple choice technology programming languages

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?

  1. The value of b is 2

  2. The value of b is 2.00

  3. The value of a is 3.141

  4. The value of a is 3.1415

Reveal answer Fill a bubble to check yourself
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.