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.
Attention reader! Don’t stop learning now. Get hold of all the important Java Foundation and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready. To complete your preparation from learning a language to DS Algo and many more, please refer Complete Interview Preparation Course.
public int intValue()
Parameters: This function accepts no parameters.
Return Value: This function returns the integer value of this BigDecimal.
Input : 19878124.176 Output : 19878124 Input : "721111" Output : 721111
Below programs illustrate the java.math.BigDecimal.intValue() method:
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.
The Integer Value of 1987812417600 is -757440448 The Integer Value of 3567128439701 is -1989383275