[resolved] Talend BigDecimal Divide operation do not work!
I am trying to divide 2 integer values and result must be decimal
For exp : pageview (12) / sessions(5) = pageviewPerSession (2,4)
I am using tConvertType to convert from INT to float or INT to BigDecimal ,
If i use float Talend works fine but I see the result value as "2" at msSQL
If i use BigDecimal at tMap : row13.pageview.divide(row13.session) gives me error (xception in component tMap_4
java.lang.NullPointerException). Also i tried (row13.pageview / row13.session) it says / is undefined.
I prefer BigDecimal because msSQL dataType is decimal(18,4), IF I choose float at msSQL there is no chance to give float(18,4) only float data type and it shows just "2" in my example.
Please help
Best Regards
Cihan
Hi Cbehen,
The error is due to your first comparison with '0'.
You already have converted
row13.session to Bigdecimal and now comparing with integer 0. Use below code to compare with decimal 0-
row13.session== java.math.BigDecimal("0")
Hope it works.
if you divide 2 integer values the result will always be an integer. You must cast at least one value to float and not only the result! I suggest also use the type double instead of float!
Hello I am converting INT to BigDecimal or INT to float at tConvertType before sending the data to the tMap Problem here is sum of sessions are sometimes zero so when i try to divide pageviews/sessions gives me nullexception This doesn't work : row13.session ==0?"do nothing":row13.pageview.divide(row13.session) Error message : Incompatible operand types BigDecimal and int. There is no double datatype at msSQL so i am trying to do this division by using BigDecimal.
Hi Cbehen,
The error is due to your first comparison with '0'.
You already have converted
row13.session to Bigdecimal and now comparing with integer 0. Use below code to compare with decimal 0-
row13.session== java.math.BigDecimal("0")
Hope it works.