Hallo, I have a temp variable BigDecimal, I want it to be reused in the function. Is there a way for me to reset this variable to zero if the value is greater than zero?
Thank @!
BigDecimal is immutable and instances cannot be modified. However, you can do something like:
public void myMethod(BigDecimal b) { BigDecimal zero = BigDecimal.ZERO; if (b.compareTo(zero) > 0) b = zero; // Do stuff with b here }
You cannot change the value. BigDecimalsare immutable. You need to create a new one.
BigDecimals