[resolved] Talend BigDecimal Divide operation do not work!

One Star

[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


Accepted Solutions
One Star

Re: [resolved] Talend BigDecimal Divide operation do not work!

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.

Thanks,
Shruti

All Replies
Seventeen Stars

Re: [resolved] Talend BigDecimal Divide operation do not work!

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!
One Star

Re: [resolved] Talend BigDecimal Divide operation do not work!

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.
One Star

Re: [resolved] Talend BigDecimal Divide operation do not work!

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.

Thanks,
Shruti

15TH OCTOBER, COUNTY HALL, LONDON

Join us at the Community Lounge.

Register Now

2019 GARNER MAGIC QUADRANT FOR DATA INTEGRATION TOOL

Talend named a Leader.

Get your copy

OPEN STUDIO FOR DATA INTEGRATION

Kickstart your first data integration and ETL projects.

Download now

What’s New for Talend Summer ’19

Watch the recorded webinar!

Watch Now

Put Massive Amounts of Data to Work

Learn how to make your data more available, reduce costs and cut your build time

Watch Now

How OTTO Utilizes Big Data to Deliver Personalized Experiences

Read about OTTO's experiences with Big Data and Personalized Experiences

Blog

Talend Integration with Databricks

Take a look at this video about Talend Integration with Databricks

Watch Now