# BigDecimal intValue() Method in Java

The java.math.BigDecimal.intValue() is an in-built function which converts this BigDecimal to an integer value. This function discards any fractional part of this BigDecimal. If the result of the conversion is too big to be represented as an integer value, the function returns only the lower-order 32 bits.

Syntax:

`public int intValue()`

Parameters: This function accepts no parameters.

Return Value: This function returns the integer value of this BigDecimal.

Examples:

```Input : 19878124.176
Output : 19878124

Input : "721111"
Output : 721111
```

Below programs illustrate the java.math.BigDecimal.intValue() method:

Program 1:

 `// Java program to illustrate ` `// intValue() method ` `import` `java.math.*; ` `import` `java.io.*; ` ` `  `class` `GFG { ` `    ``public` `static` `void` `main(String[] args) ` `    ``{ ` `        ``// Creating 2 BigDecimal Objects ` `        ``BigDecimal b1, b2; ` `        ``// Assigning values to b1, b2 ` `        ``b1 = ``new` `BigDecimal(``"19878124.176"``); ` `        ``b2 = ``new` `BigDecimal(``"721111"``); ` `        ``// Displaying their respective Integer Values ` `        ``System.out.println(``"The Integer Value of "` `+ b1 + ``" is "`  `                                                ``+ b1.intValue()); ` `        ``System.out.println(``"The Integer Value of "` `+ b2 + ``" is "` `                                                ``+ b2.intValue()); ` `    ``} ` `} `

Output:

```The Integer Value of 19878124.176 is 19878124
The Integer Value of 721111 is 721111
```

Note: Information regarding the overall magnitude and precision of large this BigDecimal values might be lost during the course of conversion by this function. As a consequence, a result with the opposite sign might be returned.

Program 2: This program illustrates a scenario when the function returns a result with the opposite sign.

 `// Java program to illustrate ` `// intValue() method ` `import` `java.math.*; ` `import` `java.io.*; ` ` `  `class` `GFG { ` `    ``public` `static` `void` `main(String[] args) ` `    ``{ ` `        ``// Creating 2 BigDecimal Objects ` `        ``BigDecimal b1, b2; ` `        ``// Assigning values to b1, b2 ` `        ``b1 = ``new` `BigDecimal(``"1987812417600"``); ` `        ``b2 = ``new` `BigDecimal(``"3567128439701"``); ` `        ``// Displaying their respective Integer Values ` `        ``System.out.println(``"The Integer Value of "` `+ b1 + ``" is "` `+ b1.intValue()); ` `        ``System.out.println(``"The Integer Value of "` `+ b2 + ``" is "` `+ b2.intValue()); ` `    ``} ` `} `

Output:

```The Integer Value of 1987812417600 is -757440448
The Integer Value of 3567128439701 is -1989383275
```

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 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.