I can't seem to locate an 'add and assign' method in the BigDecimal class.
Is there a method for this?
In case you don't understand my question I'm trying to do this:
a += b;
but I'm trying to do it with BigDecimals
I can't seem to locate an 'add and assign' method in the BigDecimal class.
Is there a method for this?
In case you don't understand my question I'm trying to do this:
a += b;
but I'm trying to do it with BigDecimals
There is an add
method in the BigDecimal
class.
You would have to do - a = a.add(b);
Have a look at the java docs.
I guess you would like something like this:
BigDecimal bd = getNumber();
bd.addAndAssign(5);
BigDecimal
is an immutable object, so no, you cannot do that.
You must use add()
and equal it to itself, e.g. a = a.add(b)
You can use the BigDecimal#add() method .
a = a.add(b);
Since BigDecimal is immutable , you cannot expect a.add(b)
to mutate a
. You have to return the new BigDecimal
object to the reference a
. Hence a=a.add(b)
is what you need.
BigDecimals are objects. the +=
operator only works with primitives.
So I don't think you can do what you are trying to propose.