Java bigdecimal class intValueExact() method transforms bigdecimal value exactly in to integer type values.
Java BigDecimal intValueExact example
Java bigdecimal class intValueExact() method transforms
bigdecimal value exactly in to integer type values.
Method throws NumberFormatException if it value other than a integer or double.
And also throws an ArithmeticException when rounding is necessary.
In the example four bigdecimal
objects namely: ganymede_0, ganymede_1, ganymede_2 & ganymede_3 respectively
have been created.
In the example MathContext class object mc is created for rounding the objects value.
In the example along with method generated result, original BigDecimal value is also shown.
Syntax for using the method: public int intValueExact()
System.out.println(bigdecimal_objectName.intValueExact());
or
int i = (this.object).intValueExact();
Java_BigDecimal_intValueExact.java
import java.math.BigDecimal;
|