Java Math Bigdecimal Multiply_mc


Java Math Bigdecimal Multiply_mc

package com.codingdict;



import java.math.*;



public class BigDecimalDemo {



   public static void main(String[] args) {



      // create 3 BigDecimal objects

      BigDecimal bg1, bg2, bg3;



      MathContext mc = new MathContext(4); // 4 precision



      bg1 = new BigDecimal("2.310");

      bg2 = new BigDecimal("4.620");



      // multiply bg1 with bg2 using mc

      bg3 = bg1.multiply(bg2, mc);



      String str = "Multiplication Result is " +bg3;



      // print bg3 value

      System.out.println( str );

   }

}