
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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)

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
