One Star

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.
2 REPLIES
Fifteen Stars

Re: Multiply 2 BigDecimal - java error

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
Rilhia Solutions
One Star

Re: Multiply 2 BigDecimal - java error

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 Smiley Happy
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.