Thanks:  0
Likes:  0
Dislikes:  0

1. ## adding large sum of numbers

Hi,

I need to add all the numbers inside an array. Each number is so large that when I check the sum, it is giving me something like 1.2e+...
How do I get the actual value without the "e+"?

2. ## Re: adding large sum of numbers

Once you reach a point and the number goes into scientific notation, that is the only number you are going to be able to retrieve.

The only other way I think of off the top of my head is that instead of writing/storing the information into an array in memory, you might have to utilize a ddt table or XML format to control the number of significant digits per your requirement.

3. ## Re: adding large sum of numbers

You could build a calculation function on your own by transfering your numbers into arrays of single digits, adding these digits (into a new array) and then converting it back to a numeric string.

If you are using big numbers this way you should "tell" WR that they should be handled as string. This can be done by preceding a string character (e.g. "_123543892371203128323423423"). When converting this string number into an array of digits you'll have to leave out the preceding string character, and when converting the summary array back to a numeric string, you will have to add the preceding string character again.

Regards,
Juergen

4. ## Re: adding large sum of numbers

Use sprintf:

num = 99 ^ 11;
pause(num);#Displays 8.953383e+021
num = sprintf("%f",num);
pause(num); #Displays 8953382542587163800000.000000

[ 01-26-2006, 07:41 AM: Message edited by: bpolitzer ]

5. ## Re: adding large sum of numbers

Hi guys,

interesting replies. I'll try each suggestion thanks [img]images/icons/smile.gif[/img]

As for Bru's suggestion. Is it going to be like this:

ex. number1 = 123
number2 = 456 *number1 & number 2 are arrays

number1[1] = 1 , number1[2] = 2, number1[3] = 3
number2[1] = 4 , number2[2] = 5, number2[3] = 6

Isn't it going to be hard to add them if each digits are on a different cell?

6. ## Re: adding large sum of numbers

I would convert the numbers into an array in different order, like that:
number1 = 123
number2 = 49
number1[1] = 3, number1[2] = 2, number1[3] = 1
number2[1] = 9, number2[2] = 4, number2[3] = "" (or 0)

Now you can put a for-loop around it (in this case from 1 to 3) and add the 2 values:
</font><blockquote><font size="1" face="Verdana, Arial, Helvetica">code:</font><hr /><pre style="font-size:x-small; font-family: monospace;">sum[i] = number1[i]+number2[i]+somewhatFromThePreviousDigit;
somewhatFromThePreviousDigit = int(sum[i]/10);
sum[i] = sum[i] % 10;</pre><hr /></blockquote><font size="2" face="Verdana, Arial, Helvetica">That's the main task for adding the 2 arrays.

Regards,
Juergen

7. ## Re: adding large sum of numbers

Juergen:

Can I file a defect?

</font><blockquote><font size="1" face="Verdana, Arial, Helvetica">code:</font><hr /><pre style="font-size:x-small; font-family: monospace;">number1[1] = 3;
number1[2] = 2;
number1[3] = 1;
number2[1] = 9;
number2[2] = 4;
number2[3] = &quot;&quot;;
for(i = 1; i &lt;= 3; i++)
{
sum[i] = number1[i]+number2[i]+somewhatFromThePreviousDigit;
somewhatFromThePreviousDigit = int(sum[i]/10);
sum[i] = sum[i] % 10;
}
for(ii in sum)
my_sum = my_sum &amp; sum[ii];
if (my_sum == (123 + 49))
pause(&quot;Code works&quot;
else
pause(&quot;What's up Juergen?&quot; #else block executed</pre><hr /></blockquote><font size="2" face="Verdana, Arial, Helvetica">

8. ## Re: adding large sum of numbers

Defect rejected:

</font><blockquote><font size="1" face="Verdana, Arial, Helvetica">code:</font><hr /><pre style="font-size:x-small; font-family: monospace;">number1[1] = 3;
number1[2] = 2;
number1[3] = 1;
number2[1] = 9;
number2[2] = 4;
number2[3] = &quot;&quot;;
for(i = 1; i &lt;= 3; i++)
{
sum[i] = number1[i]+number2[i]+somewhatFromThePreviousDigit;
somewhatFromThePreviousDigit = int(sum[i]/10);
sum[i] = sum[i] % 10;
}
for(ii in sum)
my_sum = sum[ii] &amp; my_sum; #change was made in this line
if (my_sum == (123 + 49))
pause(&quot;Code works&quot; #if block executed
else
pause(&quot;What's up Juergen?&quot;</pre><hr /></blockquote><font size="2" face="Verdana, Arial, Helvetica">

9. ## Re: adding large sum of numbers

Too bad this isn't C++. We could overwrite the + operator.

I'm afraid I need to re-open.
Doesn't work if number1 is changed to 999 :

</font><blockquote><font size="1" face="Verdana, Arial, Helvetica">code:</font><hr /><pre style="font-size:x-small; font-family: monospace;">number1[1] = 9;
number1[2] = 9;
number1[3] = 9;
number2[1] = 9;
number2[2] = 4;
number2[3] = &quot;&quot;;
for(i = 1; i &lt;= 3; i++)
{
sum[i] = number1[i]+number2[i]+somewhatFromThePreviousDigit;
somewhatFromThePreviousDigit = int(sum[i]/10);
sum[i] = sum[i] % 10;
}
for(ii in sum)
my_sum = sum[ii] &amp; my_sum;
if (my_sum == (999 + 49))
pause(&quot;Code works&quot;
else
pause(&quot;What's up Juergen?&quot; #Else block executed</pre><hr /></blockquote><font size="2" face="Verdana, Arial, Helvetica">

10. ## Re: adding large sum of numbers

what if the numbers have decimal places?

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•
Search Engine Optimisation provided by DragonByte SEO v2.0.36 (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.