Hey guys I'm currently working with talend and have to calculate some KPI's.
I'm getting the ArithmeticException: Division by zero every time now even if I follow the same schema in different calculations and they work without problems.
(((functions_pattern.checkIfNull(opportunities1.tatsaechlicherumsatz)) ==
BigDecimal.ZERO) || ((functions_pattern.checkIfNull(rechnung1.netto)) ==
BigDecimal.ZERO))
? BigDecimal.ZERO
: (rechnung1.netto.divide(opportunities1.tatsaechlicherumsatz ,
java.math.MathContext.DECIMAL32))
functions_pattern.checkIfNull sets a null value to zero (in this case BigDecimal.ZERO) I also tried various variations on this (separate null checking etc.)
Also since I'm working with talend I have to use ternary operators.
Using
==to test aBigDecimalis a bad idea.Even assuming that
checkIfNullreturnsDecimal.ZEROwhennull, you still have the problem thatrechnung1.nettocould have been a zero that is!=Decimal.ZERO.Also
equalshas the problem that both the value and the scale must be equal for twoBigDecimalvalues to be considered equal.This is the safe way to test a (non-null)
BigDecimalvalue for zero: