Rounding

public double round (double num, int digit)
{
double num2 = num * Math.pow (10, digit);
double num3 = (num2 - ((int) num2)) * 10;
num2 = ((int) num2);
if (num3 >= 5)
num2++;
return num2 /= Math.pow (10, digit);
}

For example:

Here is an entire program so that you can try it out:

public class rounding
   {
   public static void main (String args [])
   {
   new rounding ();
   }
 public rounding ()
   {
   double x = 5;
   double y = 9;
   double percent = x / y * 100;
   System.out.println ("Pre-rounding: " + percent);
   System.out.println ("As a cost: $" + round (percent, 2) + ".");
   System.out.println ("As a percent: " + round (percent, 0) + "%");
   }
 public double round (double num, int digit)
   {
   double num2 = num * Math.pow (10, digit);
   double num3 = (num2 - ((int) num2)) * 10;
   num2 = ((int) num2);
   if (num3 >= 5)
   num2++;
   return num2 /= Math.pow (10, digit);
   }
   } //class closing bracket!