[resolved] Error The operator + is undefined for the argument type(s) java.math.B

One Star

[resolved] Error The operator + is undefined for the argument type(s) java.math.B

Hi,
I need to do sum multiple column in tMap which is the data type is big Decimal.
On tmap, i set the expression as below 
row1.valueA+row1.valueB+row1.valueC+row1.valueD+row1.valueE+row1.valueF+row1.valueG+row1.valueH
Please advice the best way how to do multiple summation in talend.

Accepted Solutions
Six Stars JR
Six Stars

Re: [resolved] Error The operator + is undefined for the argument type(s) java.math.B

Hi
Simple operators like "+" or "-" do not work for the Java data type BigDecimal. You will have to use the "add" method of the BigDecimal class. To add two BigDecimals this will look like this: 
row1.valueA.add(row1.valueB)

If you want to add more than two values, you will need to nest the calls:
row1.valueD.add(row1.valueC.add(row1.valueB.add(row1.valueA)))

The result will be a BigDecimal.

All Replies
Six Stars JR
Six Stars

Re: [resolved] Error The operator + is undefined for the argument type(s) java.math.B

Hi
Simple operators like "+" or "-" do not work for the Java data type BigDecimal. You will have to use the "add" method of the BigDecimal class. To add two BigDecimals this will look like this: 
row1.valueA.add(row1.valueB)

If you want to add more than two values, you will need to nest the calls:
row1.valueD.add(row1.valueC.add(row1.valueB.add(row1.valueA)))

The result will be a BigDecimal.
One Star

Re: [resolved] Error The operator + is undefined for the argument type(s) java.math.B

Thank you. It work very well...