
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Issue can't divide BigDecimal by BigDecimal in tMap
Hi everyone
I have an issue and can't figure out the problem Talend has
First I tried to except division by zero and the next line is just divide column1 by column2
row1.Sales.equals(0)|| row1.Purchase.equals(0) ? new BigDecimal(0): row1.Sales.divide(row1.Purchase, 6, BigDecimal.ROUND_CEILING)
But I get this message
java.lang.ArithmeticException: / by zero at java.math.BigDecimal.divideAndRound(Unknown Source) at java.math.BigDecimal.divide(Unknown Source) at java.math.BigDecimal.divide(Unknown Source)
What does it mean "unknown source"?
Thanks for any hints.
Accepted Solutions

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello,
Could you try this :
BigDecimal.ZERO.compareTo(row1.Purchase)==0?new BigDecimal(0): row1.Sales.divide(row1.Purchase, 6, BigDecimal.ROUND_CEILING)

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello,
Could you try this :
BigDecimal.ZERO.compareTo(row1.Purchase)==0?new BigDecimal(0): row1.Sales.divide(row1.Purchase, 6, BigDecimal.ROUND_CEILING)

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Still get the same error.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Are you sure the error comes from this portion of code?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks now it works, maybe I did a mistake in my code.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Good news, I should have explain more in details.
Technically speaking, with this code:
row1.Purchase.equals(0)
You are trying to compare a BigDecimal with 0.
.equals() returns "true if and only if the specified Object is a BigDecimal whose value and scale are equal to this BigDecimal's." which is clearly not the case here!
Moreover, equals will compare two BigDecimal on value and scale, which means that even this would fail:
BigDecimal bd1=new BigDecimal("0"); BigDecimal bd2=new BigDecimal("0.0"); bd1.equals(bd2) // will return false
You should use compareTo() in order to compare the value only.
