Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Qlik Open Lakehouse is Now Generally Available! Discover the key highlights and partner resources here.
cancel
Showing results for 
Search instead for 
Did you mean: 
RThammisetti9330
Contributor
Contributor

Dividing two fields (Big Decimal) . getting divide by zero error

Hi,

I just need to divide two fields which are defined as big decimal data type.

for example, receivables/sales. below is my actual rule. I am checking if the fields dont have zeroes in them. Below code is failing with "java.lang.ArithmeticException: / by zero". Can anyone help me please.

(row7.avgrecievables!=BigDecimal.valueOf(0) && row4.sales!=BigDecimal.valueOf(0) ) ?

row7.avgrecievables.divide(row4.sales, 3, BigDecimal.ROUND_HALF_UP) : new BigDecimal(0) 

Labels (2)
1 Reply
SamuelLenk
Contributor
Contributor

You have an AND (&&) check there for your two input columns, It should be OR (||) and it will work 😁

But still to check if your divisor is "0" you should rather do this:

(BigDecimal.ZERO.compareTo(input_row.bigDivisor) == 0) ? BigDecimal.ZERO : input_row.bigDividend.divide(input_row.bigDivisor)

HTH! Kind regards, Samuel

https://talend-training.com/