How can I round off the output of my program?
<p>here is my programme</p>

<pre><code>package newton.raphson;


import java.util.Scanner;


public class NewtonRaphson 
{

public static void main(String[] args) 
{
 double x,f;
 int n = 0;

 Scanner s = new Scanner(System.in);
 System.out.println("enter how many times you want it to work ");     
 n=s.nextInt();   
 System.out.println("enter the value of x");
 x=s.nextDouble();
 for (int i=1;i&lt;=n;i++)
 {
 x=((2*(x*x*x)-1)/(3*(x*x)-3));
 System.out.println("x"+i+"="+x);         
 f=(x*x*x)-(x*3)+1;      
 System.out.println("f("+i+")="+f); 
 }
 }
 })
</code></pre>

<p>and the output is this</p>

<pre><code> enter how many times you want it to work 
 4
 enter the value of x
 .5
 x1=0.3333333333333333
 f(1)=0.03703703703703698
 x2=0.34722222222222227
 f(2)=1.9558041838130258E-4
 x3=0.347296353163868
 f(3)=5.724778762150606E-9
 x4=0.3472963553338607
 f(4)=-2.220446049250313E-16
</code></pre>

<p>the output of f(i) is wrong  and f(3) and f(4) nearly have the same x but giving<br>
 different output  and how can i round the answers to 5 number after the comma</p>
