Java Math Bigdecimal DivideAndRemainder_mc


Java Math Bigdecimal DivideAndRemainder_mc

package com.codingdict;



import java.math.*;



public class BigDecimalDemo {



   public static void main(String[] args) {



      // create 2 BigDecimal objects

      BigDecimal bg1, bg2;



      bg1 = new BigDecimal("143.145");

      bg2 = new BigDecimal("10.01");



      MathContext mc = new MathContext(2);



      // BigDecimal array bg stores result of bg1/bg2,

      // using mc 

      BigDecimal bg[] = bg1.divideAndRemainder(bg2, mc);



      // print quotient and remainder

      System.out.println("Division result");

      System.out.println("Quotient is " + bg[0] );

      System.out.println("Remainder is " + bg[1] );

   }

}