# Working With Large Numbers? How?

## Recommended Posts

Hello,

I just scripted something to convert a file in csv format to a file in a format to transfer to the bank (dtaus).(Script works but, only if things are not beyond limits) The csv format was saved from Open Office and contained banktransfer informations example:

Name of recipient, sum, banknumber, bankaccountnumber, reason for payment

Mighty Jon,50000,38638650,12345, deb. nr. 5432

J.B.E, 34000, 38650023,121212,deb. nr. 3456

The problem is that the bankaccountnumber can have up to 10 digits.

The checksum used by the bank can have up to 17 digits. (Its just all bankaccountnumbers summed up). Both is beyond AutoIts current limits.

Is there allready a known workaround, perhaps a udf to break that limit.

Or any other way to get somthing like a double long int ? I searched the formum but did not find anything. I´ll try to code something myself if there is no solution avaible at the moment. I just wanted to ask first, becaus if there is allready a solution, it would save me time

commenti

##### Share on other sites

Hi Jon,

thank you but I´ve to calculate with them (especially summing up), does this work if they are strings? Plus I´ve the problem I need to format them with leading zeros, if they are to short. For example 12345 must bei 0000012345. With "%010u" its easy but with a string I can only have blanks insewrted. Ok, I can repace the blanks with zeros bevor output but what still makes me headaches is that I need to sum up all the numbers. I did not try to sum up two strings, I´ll try...

commenti

##### Share on other sites

If you're sure you want to use AutoIt for this you can use bc (from http://unxutils.sourceforge.net) to do the calculations. bc doesn't care how big the numbers are. it's even possible to calculate 99999999^1000 with bc.

Just treat the numbers as strings within AutoIt and for the calculations write the calculation to a file and let bc do the work.

##### Share on other sites

Oh, thank you sugi! (Or should I say "Danke!"? at least you have the same time zone....).

I just tried out the bc programm you suggest. I think its a good workaround. I am sure I want to do it with AutoIt. My script was allready finished when I wrote my question. Only summing up all bankaccount numbers did not work and 2 of my "lot off" input data records had too big account numbers. With bc I can easily ship around that cliff, thanx again. I´ll still try out to solve this completly with AutoIt without using external apps, just because I am curious if it is possible. (But this has time, now that my script is completly working with the help of bc).

commenti

##### Share on other sites

Yes, I'm german

It is possible without using an external app but you'd have to write your own function to calculate with the numbers.

Basically the function would have to work like this:

- Get last digit of both numbers

- write last digit of the sum to the string containing the result

- If the sum of these digits are bigger than 9, make a note that you have to add 1 for the next pass

- Do the same with the next digits until you've reached the beginning of the number

But if you have a lot numbers I'd still suggest to use bc for this as it will be a lot faster.

##### Share on other sites

Like this UDF:

I used it for summing very big numbers. In a similar situation.

I can only Sum and it accept only positive numbers... Easy as that.

```_SumStrings("123456789012345678901234567890","564815646864751345687456123")

Local \$Lenght, \$tocarry = 0, \$Sum = "", \$c, \$SubTotal

Exit
EndIf

Else
EndIf
If \$Lenght <= 3 Then
\$Lenght = 3
Else
\$Lenght = \$Lenght + Mod(\$Lenght,3)
EndIf

Wend

Wend

For \$c = 1 to \$Lenght/3
If \$SubTotal > 999 Then
\$ToCarry = Int(\$SubTotal/1000 )
Else
\$ToCarry = 0
EndIf
String(\$SubTotal)
While StringLen(\$SubTotal) < 3
\$SubTotal = "0" & \$SubTotal
Wend
\$Sum = StringRight(\$Subtotal,3) & \$Sum

Next

While StringInStr(\$sum,"0") = 1
\$Sum = StringTrimLeft(\$sum,1)
Wend
Msgbox(0,"",\$sum)

EndFunc```
Edited by ezzetabi

##### Share on other sites

Hello sugi, hello ezzetabi,

first : Thank you again sugi. DC works really well, its easy to let autoit extract the numbers from the csv file that have to be summed up and then write them in a tempfile for dc. After that dc can sum up all together, because its scriptable itself: good OT: Your avatar, whats that? Are you an anmie fan? ( I am, but I can´t tell from wiitch anime this is taken from, my favorite is "noir" perhaps you know that one, too).

second: Thank you ezzetabi

The udf would be exactly what I had needed if I did not solve this with dc, that sugi suggested (and which works well). Bank account nummbers are never negativ, and I really only needed to sum them up. The bank uses this as "checksum". But even if my current problem was solved thanks to sugi, i´ll have a deeper look in your udf to see how its done. You can never learn enough

commenti

## Create an account

Register a new account

×

• Wiki

• Back

• Git