In this example working of .add() method is demonstrated in following two
constructor forms add(BigDecimal augend) and add(BigDecimal augend, MathContext mc) respectively. Method returns the addition result of two
bigdecimal class objects values. And the returned value is itself a bigdecimal value
which means the result generated, has to stored by a bigdecimal object (provided the result is not converted and type casted to nay
In the example two bigdecimal objects obj_0 and obj_1 values
are added and the result is stored in object obj_3.
Also the addition result of objects obj_4 & obj_5 are stored in object obj_6. Object obj_6 contains addition
result as per context settings defined under MathContext class
objects mc and nc respectively.
Syntax for using add method :
public BigDecimal add(BigDecimal augend),
public BigDecimal add(BigDecimal
augend, MathContext mc)
Scale associated to the result is computed through bigdecimal
class max method. .max()
method compares the this.object scale with the
scale of the object specified & returns scale which maximum!greater.
In the example for formating purpose two new classes NumberFormat
& Locale are included.
Method throws NumberFormatException if it finds a value other than a integer or double value.