Java Math Bigdecimal Divide Integral Value mc


Java Math Bigdecimal Divide Integral Value mc

package com.codingdict;



import java.math.*;



public class BigDecimalDemo {



   public static void main(String[] args) {



      // create 3 BigDecimal objects

      BigDecimal bg1, bg2,bg3;



      bg1 = new BigDecimal("99.8");

      bg2 = new BigDecimal("3");



      MathContext mc = new MathContext(2);



      // divide bg1 with bg2 using mc

      bg3 = bg1.divideToIntegralValue(bg2, mc);



      String str = "Integer part of division result using mc is " +bg3;



      // print bg3 value

      System.out.println( str );

   }

}