Rounding up a float or a double

Use the ceil method in the Math class. It rounds up to the next higher integer:

import java.math.*;
                           
public class Main 
{  
   public static void main(String args[]) throws Exception {
      double d1 = 1.3, 
             d2 = 1.8,
             d3 = -1.3, 
             d4 = -1.8;
 
      System.out.println(Math.ceil(d1));
      System.out.println(Math.ceil(d2));
      System.out.println(Math.ceil(d3));
      System.out.println(Math.ceil(d4));
   }
}

outputs:

2.0
2.0
-1.0
-1.0