Java Math Bigdecimal pow_mc


Java Math Bigdecimal pow_mc

package com.codingdict;



import java.math.*;



public class BigDecimalDemo {



   public static void main(String[] args) {



      // create 2 BigDecimal Objects

      BigDecimal bg1, bg2;



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



      bg1 = new BigDecimal("2.17");



      // apply pow method on bg1 using mc

      bg2 = bg1.pow(3, mc);



      String str = "The value of " + bg1 + " to the power of 3, rounded to " + bg2;



      // print bg2 value

      System.out.println( str );

   }

}