setItem value "0", when calculated value <= "0"

Hi,

I’ve implemented this method:
protected boolean preCommit() {
BigDecimal schijf3 = getItem()
.getSchijf3()
.multiply(valueOf(getItem().getPercentageSchijf3()));
getItem().setAfdrachtSchijf3(schijf3);
return super.preCommit();

I works fine, but now I want it to set the “setAfdrachtSchijf3” to “0” if the value of “getSchijf3” <=“0” .
Any help would be welcome.

ps All the values are bigdecimal.

Hi.
You should compare your BigDecimal value with zero.
Here is an example how it could be implemented:

protected boolean preCommit() {
    BigDecimal schijf3 = new BigDecimal(0);
    BigDecimal value = getItem()
				  .getSchijf3();
    if (value.compareTo(BigDecimal.ZERO) > 0){
	schijf3 = value.multiply(valueOf(getItem().getPercentageSchijf3()));
    }
    getItem().setAfdrachtSchijf3(schijf3);
    return super.preCommit();
}

More information about BigDecimal

Regards,
Nadezhda

1 Like

Thanks Nadezhda.