Java BigDecimal toBigInteger()

PreviousNext

The java.math.BigDecimal.toBigInteger() converts this BigDecimal to a BigInteger.

Following is the declaration for java.math.BigDecimal.toBigInteger() method.

public BigInteger toBigInteger()

Return Value

This method returns the value of BigDecimal object converted to a BigInteger.

The following example shows the usage of math.BigDecimal.toBigInteger() method.

import java.math.*;

public class Main {

   public static void main(String[] args) {

      // create a BigDecimal object
      BigDecimal bg1;/* w   w  w .  d  e m    o  2  s.   c   o  m*/

      // create a BigInteger object
      BigInteger i1;

      bg1 = new BigDecimal("123.123");

      // assign the BigInteger value of bg1 to i1
      i1 = bg1.toBigInteger();

      String str = "BigInteger value of " + bg1 + " is " + i1;

      // print i1 value
      System.out.println( str );
   }
}

Result

PreviousNext

Related