Rounding a BigDecimal

You can use one of the numerous rounding modes.

Main.java:

import java.math.*;
  
public class Main {
   public static void main(String args[]) {
      BigDecimal bd = new BigDecimal("3");          // 3/2=1.5
 
      System.out.println("ROUND_CEILINGt"   + bd.divide(new BigDecimal("2"), 
         BigDecimal.ROUND_CEILING));
      System.out.println("ROUND_DOWNt"      + bd.divide(new BigDecimal("2"), 
         BigDecimal.ROUND_DOWN));
      System.out.println("ROUND_FLOORt"     + bd.divide(new BigDecimal("2"), 
         BigDecimal.ROUND_FLOOR));
      System.out.println("ROUND_HALF_DOWNt" + bd.divide(new BigDecimal("2"), 
         BigDecimal.ROUND_HALF_DOWN));
      System.out.println("ROUND_HALF_EVENt" + bd.divide(new BigDecimal("2"), 
         BigDecimal.ROUND_HALF_EVEN));
      System.out.println("ROUND_HALF_UPt"   + bd.divide(new BigDecimal("2"), 
         BigDecimal.ROUND_HALF_UP));
      System.out.println("ROUND_UPt"        + bd.divide(new BigDecimal("2"), 
         BigDecimal.ROUND_UP));
      System.out.println("ROUND_UNNECESSARYt" + bd.divide(new BigDecimal("2"), 
         BigDecimal.ROUND_UNNECESSARY));
   } 
}

outputs:

ROUND_CEILING	2
ROUND_DOWN		1
ROUND_FLOOR		1
ROUND_HALF_DOWN	1
ROUND_HALF_EVEN	2
ROUND_HALF_UP	2
ROUND_UP		2
Exception in thread "main" java.lang.ArithmeticException: Rounding necessary
        at java.math.BigDecimal.divide(BigDecimal.java:344)
        at java.math.BigDecimal.divide(BigDecimal.java:403)
        at Main.main(Main.java:21)

Explanation:

ROUND_CEILING:        (always towards positive infinitive)
   0.3  rounds to  1, 
   -0.9 rounds to  0   
ROUND_DOWN:           (always rounds towards zero)
   0.3  rounds to  0, 
   0.9  rounds to  0, 
   -0.9 rounds to  0  
ROUND_FLOOR:          (always rounds towards negative infinity)
   0.3  rounds to  0
   0.9  rounds to  0
   -0.3 rounds to -1
ROUND_HALF_DOWN:      (rounds to the neirest distance, if .5: round to zero)
   0.3  rounds to  0
   0.9  rounds to  1
   -0.9 rounds to -1
   0.5  rounds to  0
   -0.5 rounds to  0
ROUND_HALF_EVEN:      (rounds to the neirest distance, if .5: round to neirest even)
   0.3  rounds to  0
   -0.9 rounds to -1
   0.5  rounds to  0
   -0.5 rounds to  0
   1.5  rounds to  2 
   -1.5 rounds to -2
   2.5  rounds to  2
   -2.5 rounds to -2
ROUND_HALF_UP:        (rounds to the neirest distance, if .5: round away from zero)
   0.3  rounds to  0
   0.9  rounds to  1
   -0.9 rounds to -1
   0.5  rounds to  1
   -0.5 rounds to -1
ROUND_UP:             (always round away from zero)
   0.3  rounds to  1
   -0.3 rounds to -1
   0.5  rounds to  1
   -0.5 rounds to -1