One Star

How to convert bigDecimal to double

Hello,
I have a AS400 database that contains data with decimal type.
when I loaded the data ,Talend convert the Decimal type to BigDecimal .
And for the destination I have a postgres database .
when I made the connection between the two databases using a tmap component. this error msg appears:
Exception in thread "main" java.lang.Error: Problèmes de compilation non résolus :
Non concordance de types : impossible de convertir de BigDecimal en double
Non concordance de types : impossible de convertir de BigDecimal en double
Non concordance de types : impossible de convertir de BigDecimal en double
8 REPLIES
Seventeen Stars

Re: How to convert bigDecimal to double

hi asterisks,
first Talend use a Xml file to Map DB type to JavaType (also known as Talend Type) and 'vice-versa'.
There is no implicit cast between type.
So you can't change the way Talend Map conversion Type by Default.
You have to convert type if necessary ; for that purpose use tConvertType.
BE AWARE about java type for decimal and loosing precision with floating type like Float & Double
hope it helps
regards
laurent
Seventeen Stars

Re: How to convert bigDecimal to double

You will not losing any precision if you only transfer data also on Double.
You should use an expression in your tMap:
row1.my_big_decimal != null ? row1.my_big_decimal.doubleValue() : null
Seventeen Stars

Re: How to convert bigDecimal to double

hi all,
Because floating-point numbers have a limited number of digits, they cannot represent all real numbers accurately: when there are more digits than the format allows, the leftover ones are omitted - the number isrounded.
You will not losing any precision if you only transfer data also on Double

You mean if you make any calculation on decimal and JUST propagate value through the flows !?
regards
laurent
One Star

Re: How to convert bigDecimal to double

hello Mr.JLOLLING,
Can you please tell me,where exactly I'll put the expression....
Regards,
Moderator

Re: How to convert bigDecimal to double

Hi,
Please have a look at screenshot
Best regards
Sabrina
--
Don't forget to give kudos when a reply is helpful and click Accept the solution when you think you're good with it.
One Star

Re: How to convert bigDecimal to double

hello,
it works, thank you a lot
Best regards
Moderator

Re: How to convert bigDecimal to double

Hi,
Thanks for your feedback. Could you please click the "Set this topic as resolved" link which is right underneath your initial post? This way, other users will be informed that this thread has been resolved.
Many thanks
Best regards
Sabrina
--
Don't forget to give kudos when a reply is helpful and click Accept the solution when you think you're good with it.
Five Stars

Re: How to convert bigDecimal to double

@jlolling
Thanks for the expression   
May you can give a short exaplaination what he expression does  
Will be helpful  
Additional: Could i use the expression for an Fieldlookup also or only for  mapping. 
Thanks in advance 
regards fireskyer