Bigdecimal value remains zero

Hi there,

I’m trying to multiply two bigdecimal values. If i leave this “BigDecimal exchangeRate = BigDecimal.ZERO;”, i get a null pointer exception. If i place it in my code the result of the multiplication is “0”. If i change is to Bigdecimal.TEN, the result is the value multuplied by ten. How do i get it to use the value of the field " exchangeRate"?

This is the code i use:

@Override
public void postInit(Operation item) {
amount1Field.addValueChangeListener(e -> {
BigDecimal exchangeRate = BigDecimal.ZERO;
if (e.getValue() != null && StringUtils.isBlank(amount2Field.getValue())) {
amount2Field.setValue(String.valueOf(exchangeRate.multiply(new BigDecimal(e.getValue()))));
}
});
}

It seems like the value of the “exchangeRate” is ignord.

Thanks in advance

LS

Hi.

Can you explain in detail what you want to get as a result? It looks like it works clear now.

Hi,

As result i want “exchangeRate” multiplied with “e.getValue”, that doesn’t happen. So if e.g. amount1Field is 100 and exchangeRate is 19, amount2Field should be 1900.

What happens now if amount1Field is 100 and exchangeRate is 19, what will be in result?

if " BigDecimal exchangeRate = BigDecimal.ZERO;" is in the code the result is “0” . If i change it to “BigDecimal exchangeRate = BigDecimal.TEN;” the result is “1000”.

You can create BigDecimal instance with any value using constructor, for example:

BigDecimal exchangeRate = new BigDecimal(19);

or use value from any entity:

BigDecimal exchangeRate = new BigDecimal(anyEntity.getValue());

and this value will be used in multiplying.

Regards,
Nadezhda.

Thanks Nadezhda,

BigDecimal exchangeRate = new BigDecimal(anyEntity.getValue());

works fine for me.

Regards,
Lloyd