5 Replies Latest reply on Oct 24, 2008 7:15 PM by Newsgroup_User

Glitch - Sum of an ArrayCollection

Ok, so I have an ArrayCollection and a simple little formula to add the collection together. And here's the glitch:
If the array is say [0,6] then the total is 6 but if the array is [6,0] then the total is 60. How does that work?
Another example: array is [9,0] then total = 90. Array is [9,0,6] then total = 96. Array is [9,0,6,0] then total = 960. It looks to me that somehow adding 0 multiplies the number by 10, or can be looked at by adding another "0" to the end of the figure.

Any insight on how to resolve this issue would be much appreciated. Thanks!
• 1. Re: Glitch - Sum of an ArrayCollection
This works. I would check your data, like what is .cnt, does not seem like an arraycollection.
• 2. Re: Glitch - Sum of an ArrayCollection

"mattcom" <webforumsuser@macromedia.com> wrote in message
news:gdq39p\$3sa\$1@forums.macromedia.com...
> Ok, so I have an ArrayCollection and a simple little formula to add the
> collection together. And here's the glitch:
> If the array is say [0,6] then the total is 6 but if the array is [6,0]
> then
> the total is 60. How does that work?
> Another example: array is [9,0] then total = 90. Array is [9,0,6] then
> total
> = 96. Array is [9,0,6,0] then total = 960.

I think your array is probably ['9','0','6']

Hope this helps :-)

• 3. Glitch - Sum of an ArrayCollection
So perhaps its a string rather than a number... hmm... didn't think of that. Still, the arrays that are like [9,6,7,12] will add up correctly and total 34. It's just the zeros that cause problems.

I'll play around with it and make sure they are all numbers rather than strings and let you know. Thanks for the reply.
• 4. Re: Glitch - Sum of an ArrayCollection
You were right. It was taking the array collection as a string and not a number. This makes it work.

Thanks for the help guys!
• 5. Re: Glitch - Sum of an ArrayCollection

"mattcom" <webforumsuser@macromedia.com> wrote in message
news:gdtk2s\$44h\$1@forums.macromedia.com...
> You were right. It was taking the array collection as a string and not a
> number. This makes it work.
>
> Thanks for the help guys!
>
> n = type0.length;
> for (i = 0; i < n; i++)
> {
> compareTotal += parseInt(type0 .cnt);
> }
>

You're welcome :-)