One Star

[resolved] How to devide a BigDecimal value...

Hi *,
using tMap, I'm trying to devide a BigDecimal vaule by 100. Pretty simple, I thought.
Source and target fields are BigDecimal, but by using the following syntax I get an error like: "Exception in component tRowGenerator_1" by clicking the 'Test'-Button in the expression editor of the target field.
new BigDecimal(100).divide(row1.theUltimateValueWhoNeedsToGetDevidedBySomething)

What is the mistake?
Thank you!
Ben
1 ACCEPTED SOLUTION

Accepted Solutions
One Star

Re: [resolved] How to devide a BigDecimal value...

Hey Lijo,
thank you for your help! You pushed me into the right direction!
I found a second problem in my syntax: I muddled up the source value and the division value; for example:
100 divided by 15 (false)
instead of
15 divided by 100 (correct)

So the code is now working, I just needed to swap those values in the code, thanks again!
row4.MWST_SATZ.divide(new BigDecimal(100),java.math.MathContext.DECIMAL32)
6 REPLIES
One Star

Re: [resolved] How to devide a BigDecimal value...

Here is the error I get by running the job:
no exact representable decimal result.
at java.math.BigDecimal.divide(Unknown Source)
One Star

Re: [resolved] How to devide a BigDecimal value...

Is nobody able to help me out on this issue?
One Star

Re: [resolved] How to devide a BigDecimal value...

Hi
use
new BigDecimal(100).divide(row1.theUltimateValueWhoNeedsToGetDevidedBySomething,RoundingMode.HALF_UP)
One Star

Re: [resolved] How to devide a BigDecimal value...

Thank you!
But now Talend is telling me that 'RoundingMode' cannot get resolved... Would it be better to change the data type into double or something like that?
One Star

Re: [resolved] How to devide a BigDecimal value...

Hi
Sorry i didnt give fully
write java.math.RoundingMode.HALF_UP instead of RoundingMode.HALF_UP
One Star

Re: [resolved] How to devide a BigDecimal value...

Hey Lijo,
thank you for your help! You pushed me into the right direction!
I found a second problem in my syntax: I muddled up the source value and the division value; for example:
100 divided by 15 (false)
instead of
15 divided by 100 (correct)

So the code is now working, I just needed to swap those values in the code, thanks again!
row4.MWST_SATZ.divide(new BigDecimal(100),java.math.MathContext.DECIMAL32)