Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
 pawe84
		
			pawe84
		
		
		
		
		
		
		
		
	
			
		
		
			
					
		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.
 lennelei
		
			lennelei
		
		
		
		
		
		
		
		
	
			
		
		
			
					
		Hello,
Could you try this :
BigDecimal.ZERO.compareTo(row1.Purchase)==0?new BigDecimal(0): row1.Sales.divide(row1.Purchase, 6, BigDecimal.ROUND_CEILING)
 lennelei
		
			lennelei
		
		
		
		
		
		
		
		
	
			
		
		
			
					
		Hello,
Could you try this :
BigDecimal.ZERO.compareTo(row1.Purchase)==0?new BigDecimal(0): row1.Sales.divide(row1.Purchase, 6, BigDecimal.ROUND_CEILING)
 pawe84
		
			pawe84
		
		
		
		
		
		
		
		
	
			
		
		
			
					
		Still get the same error.
 lennelei
		
			lennelei
		
		
		
		
		
		
		
		
	
			
		
		
			
					
		Are you sure the error comes from this portion of code?
 pawe84
		
			pawe84
		
		
		
		
		
		
		
		
	
			
		
		
			
					
		Thanks now it works, maybe I did a mistake in my code.
 lennelei
		
			lennelei
		
		
		
		
		
		
		
		
	
			
		
		
			
					
		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.
