cancel
Showing results for 
Search instead for 
Did you mean: 

XI mapping function SUM calculate wrong?

Former Member
0 Kudos

Hi, I suspect the default SUM function in XI IB to calculate wrong on big decimal values. I tried the user defined function described at the bottom of this thread: ?

But I miss out something. It does not SUM for the whole document, as the default SUM function would do.

Any ideas?

Would any service packs correct this? Anyone else with this problem? Is it a bug?

Accepted Solutions (1)

Accepted Solutions (1)

Shabarish_Nair
Active Contributor
0 Kudos

Hi Rune,

Are you trying to calculate the sum of the a particular field in the whole of the document ?

the maybe you can try this code :

for (int i = 0; i<a.length; i++)

{

temp = Integer.parseInt(a<i>);

tempSum = tempSum + temp ;

}

As Mike suggested you have to handle the context.Make the context of the field to be summed to the immediate parent or the root.

Pass the field as input and return the value of tempSum to get the total sum.

Message was edited by: Shabarish Vijayakumar

Former Member
0 Kudos

Yes, I need to calculate for the particular field of the whole document. I struggle with a Java calulation bug that seems to be in the SUM mapping function.

This code should handle large numbers and get rid of the error:

BigDecimal d1 = new BigDecimal(a); // original number

BigDecimal d2 = d1.setScale(2, BigDecimal.ROUND_HALF_DOWN); // "normal" rnd rule

String result = d2.toString();

return result;

But I this return a value of that field, not a SUM of all fileds in the whole document (as SUM would do).

<i>I think I have to use a loop as described, but what should be in parameter b (or a)?</i>

Message was edited by: Rune Johansen

Message was edited by: Rune Johansen

Former Member
0 Kudos

Hi Rune ,

Set the context of the field to the root node on which you are trying to calculate the sum and write a user defined function and use the code as mentioned by Shabarish . You can also use <i>Double.parseDouble(b)</i> instead of the Integer wrapper Class if it truncates your decimal value.

Thanks & Regards,

Ashish Sharma .

Shabarish_Nair
Active Contributor
0 Kudos

if large numbers are involved than try double class if it suits your requirement.

for (int i = 0; i<a.length; i++)

{

<b>temp = Double.parseDouble(a);</b>

/* this will do the trick */

tempSum = tempSum + temp ;

}

and dont forget to handle your context. Put it to the root, this wud be enough.

Former Member
0 Kudos

Hi all, thanks for answers. This blog helped me out:

/people/thorsten.nordholmsbirk/blog/2006/04/03/never-ever-use-xis-built-in-arithmetic-functions

Anyone knows if there are SP that corrects this?

Answers (1)

Answers (1)

MichalKrawczyk
Active Contributor
0 Kudos

Hi,

what do you mean " It does not SUM for the whole document" ?

did you set the correct context ? if you want to sum

numbers from different nodes ?

Regards,

michal