# BigDecimal toBigInteger() Method in Java

The java.math.BigDecimal.toBigInteger() is an inbuilt method in jav that converts this BigDecimal to a BigInteger. This conversion is analogous to the narrowing primitive conversion from double to long. Any fractional part of this BigDecimal will be discarded. This conversion can lose information about the precision of the BigDecimal value.

Note: If an exception thrown in the conversion inexact (in other words if a nonzero fractional part is discarded), use the toBigIntegerExact() method.

Syntax:

```public BigInteger toBigInteger()
```

Parameters: This method does not accepts any parameters.

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

Examples:

```Input: (BigDecimal) 123.321
Output: (BigInteger) 123

Input: (BigDecimal) 123.001
Output: (BigInteger) 123```

Below programs illustrate the working of the above mentioned method:
Program 1:

 `// Program to demonstrate toBigInteger() method of BigDecimal  ` ` `  `import` `java.math.*; ` ` `  `public` `class` `GFG { ` ` `  `    ``public` `static` `void` `main(String[] args) ` `    ``{ ` ` `  `        ``// Assigning the BigDecimal b ` `        ``BigDecimal b = ``new` `BigDecimal(``"123.321"``); ` ` `  `        ``// Assigning the BigInteger value of  BigDecimal b to  BigInteger i ` `        ``BigInteger i = b.toBigInteger(); ` ` `  `        ``// Print i value ` `        ``System.out.println(``"BigInteger value of "` `+ b + ``" is "` `+ i); ` `    ``} ` `} `

Output:

```BigInteger value of 123.321 is 123
```

Program 2:

 `// Program to demonstrate toBigInteger() method of BigDecimal  ` ` `  `import` `java.math.*; ` ` `  `public` `class` `GFG { ` ` `  `    ``public` `static` `void` `main(String[] args) ` `    ``{ ` ` `  `        ``// Assigning the BigDecimal b ` `        ``BigDecimal b = ``new` `BigDecimal(``"123.001"``); ` ` `  `        ``// Assigning the BigInteger value of  BigDecimal b to  BigInteger i ` `        ``BigInteger i = b.toBigInteger(); ` ` `  `        ``// Printing i value ` `        ``System.out.println(``"BigInteger value of "` `+ b + ``" is "` `+ i); ` `    ``} ` `} `

Output:

```BigInteger value of 123.001 is 123
```

Don’t stop now and take your learning to the next level. Learn all the important concepts of Data Structures and Algorithms with the help of the most trusted course: DSA Self Paced. Become industry ready at a student-friendly price.

My Personal Notes arrow_drop_up Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

Article Tags :
Practice Tags :

Be the First to upvote.

Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.