Java bigdecimal class longValueExact() method transforms bigdecimal value exactly in to exact long type values.
Java BigDecimal longValueExact example
Java bigdecimal class longValueExact() method transforms bigdecimal value exactly in to exact long 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 class objects namely: carel_0, carel_1, carel_2 & carel_3 respectively have been created.
In the example MathContext class object nc is created for rounding objects value.
In the example along with method generated result, original
bigdecimal value is also shown.
Syntax for using the method: public long longValueExact()
System.out.println(bigdecimal_objectName.longValueExact());
or
long ln = (this.object).longValueExact();
Java_BigDecimal_longValueExact.java
import java.math.BigDecimal;
|