Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Join us in NYC Sept 4th for Qlik's AI Reality Tour! Register Now
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

Multiply 2 BigDecimal - java error

Hi everyone,

In MySQL DB the field  row8.purchasing_price is recorded as DECIMAL(16,2)
In MySQL DB the field  row10.php_to_myr is recorded as DECIMAL(16,6)
In Talend (in the tMap) the field  row8.purchasing_price is recognized as a float and I set manually the type as BigDecimal
In Talend (in the tMap) the field  row10.php_to_myr is recognized as a float and I set manually the type as BigDecimal

Theses codes below raise an error (cf. screenshot below)
code 1
row8.purchasing_price_currency.equals("PHP")
?row8.purchasing_price*row10.php_to_myr
:System.out.println("ERROR purchasing price")

code 2
row8.purchasing_price_currency.equals("PHP")
?row8.purchasing_price.multiply(BigDecimal.valueOf(row10.php_to_myr))
:System.out.println("ERROR purchasing price")

What can I do to multiply 2 BigDecimal (or float) ?
Thank you for your advice.
0683p000009MCA3.png 0683p000009MCJk.png
Labels (2)
2 Replies
Anonymous
Not applicable
Author

You have to keep in mind that Talend generates Java code and there is a requirement (particularly in Expressions) to use Java. The problem you are having here is because BigDecimal mathematics are not as simple as they are with other numeric types. This should help you.....
http://www.opentaps.org/docs/index.php/How_to_Use_Java_BigDecimal:_A_Tutorial
Anonymous
Not applicable
Author

Hi again rhall_2.0,
The tutorial is quiet good to understand why you can face some precision issue.
But in my case, I don't have any precision troubles since my code is not even able to get me a result 0683p000009MACn.png
I am going to try to work with float since Talend recognized my DECIMAL fields (in MySQL DB) as FLOAT (in tMap) by default.
Thx.