I have 2 BigDecimal
numbers. I am trying to add them. My code is as follow:
BigDecimal bd1 = new BigDecimal(10);
BigDecimal bd2 = new BigDecimal(10);
bd1.add(bd2);
Here I am expecting the value of bd1 20 but again and again it's showing 10. It's not being added. Please help if I have done something wrong.
BigDecimal
values are immutable, You need to assign the value to the result of add
:
bd1 = bd1.add(bd2);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With