Answer:
Following is the code in Java Language :
DecimalFormat form1= new DecimalFormat ("0.####"); // create an instance of . //DecimalFormat
System.out.println (form1.format(res)); // display the value in proper format
Explanation:
Following are the description of the program
- Firstly we create the instance of DecimalFormat i.e "form1" that will round a formatted value to four decimal places. To create an instance or object of the class we can use a new keyword.
- Finally, we print the format by using the format method.In the format method, we pass the variable "res".The System.out.println() is used to display the value of the format.