The java.math.BigDecimal.toBigIntegerExact() is an inbuilt method in java that converts this BigDecimal to a BigInteger, checking for lost information. An exception is thrown if this BigDecimal has a nonzero fractional part.
public BigInteger toBigIntegerExact()
Parameters: The method does not take any parameters.
Return value: This method returns the value of BigDecimal object converted to a BigInteger.
Input: (BigDecimal) 1213 Output: (BigInteger) 1213 Input: (BigDecimal) 12785412 Output: (BigInteger) 12785412
Below programs illustrates the working of the above mentioned method:
BigInteger value of 1213 is 1213
BigInteger value of 12785412 is 12785412
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.