Given below the sample code :
1 import java.text.*;
2 public class NumberformatClass {
3 public static void main(String args[]){
4 NumberFormat nf = NumberFormat.getInstance();
5 nf.setMaximumFractionDigits(4);
6 nf.setMinimumFractionDigits(2);
7 String a = nf.format(3.1415926);
8 String b = nf.format(2);
9 System.out.println(a);
10 System.out.println(b);
11 }}
The output of the above code is 3.1416, 2.00 ,What will be it's output ,if we remove line 5 & 6 ?
1. Same output.
2. It will give Compile error.
3. 3.142(4)
The default value of Maximum fraction digit (after decimal) is 3 and minimum fraction digit is 0.
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.