One Star

## Novice problem with Talend and BigDecimal

Hello,
I hope the following is not a FAQ.
I have a problem using BigDecimal (and tMap)
Practically, I have the main flow "row9" containing 2 BIGDECIMAL columns CLOTHUSAGE and SUMQTY and I need to print in a CSV file an AVG which basically is CLOTHUSAGE/(SUMQTY*10000)

btw If I extract their values they are correct..
CLOTHUSAGE SUMQTY
275021 42
445140 40
607115 220
745800 60
7047275 1300
I am using a tMap in order to add a column AVG to my main output flow
The problem is the following
If I divide one for the other with the following formula
(row9.CLOTHUSAGE != null && row9.SUMQTY != null)? row9.CLOTHUSAGE.divide(row9.SUMQTY, 0, BigDecimal.ROUND_FLOOR):new BigDecimal(0)

the results in the CSV are correct
CLOTHUSAGE SUMQTY AVG
275021 42 6548
445140 40 11128
607115 220 2759
745800 60 12430
7047275 1300 5420
But as I said I would need these numbers in a CSV in another scale (/10000) as the following
0.6548
1.1128
0.2759
1.2430
0.5420
So I have tried to set the target column of the tMap output flow as the following
(row9.CLOTHUSAGE != null && row9.SUMQTY != null)? row9.CLOTHUSAGE.divide(row9.SUMQTY.multiply(new BigDecimal(10000)), 5, BigDecimal.ROUND_FLOOR):new BigDecimal(0)

And here is the strange thing
I obtain the following unexpected (at least for me) result
0.65481
111.285 (KO)
0.27596
124.300 (KO)
0.54209
What am I doing wrong?
Thanks in advance for any suggestion
One Star

## Re: Novice problem with Talend and BigDecimal

An update...
putting a tLogRow the data I see in the console are correct, so the problem seems to be in the way I use the tFileOutputDelimited Component
VindalooMan
One Star

## Re: Novice problem with Talend and BigDecimal

A last update (and closing the issue)
This morning I have tried opening the CSV with a text editor and not with Excel (sigh) and the data are correct.
So it is a matter of visualization in Excel...
sorry for non checking it before :-|
Ciao
One Star

## Re: Novice problem with Talend and BigDecimal

Hello,
I reproduced your job and it works. The good values are contained in the tFileOutputDelimited component
i use TOS v4.02.r43696
Regards
One Star

## Re: Novice problem with Talend and BigDecimal

hi
Can we compare BigDecimal value with null ,i tried using row1.col==null?0:row1.col
but getting the following error in tmap
Type mismatch:cannot convert from number and comparable<?>to BigDecimal

how to compare it with null value
Seven Stars

## Re: Novice problem with Talend and BigDecimal

0 is an int so you can't assign it to a BigDecimal column. Use row1.col==null?BigDecimal.ZERO:row1.col.