Sign in to follow this  
Followers 0
commenti

Working With Large Numbers? How?

8 posts in this topic

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 :ph34r:

commenti

Share this post


Link to post
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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
Share on other sites

Yes, I'm german :ph34r:

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

- Add both digits

- 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 this post


Link to post
Share on other sites

#7 ·  Posted (edited)

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")

Func _SumStrings($addend1,$addend2)
   Local $Lenght, $tocarry = 0, $Sum = "", $c, $SubTotal
   If Not IsString($addend1) Then $addend1 = String(Int($Addend1))
   If Not IsString($addend2) Then $addend2 = String(Int($Addend2))

   If not StringIsInt($addend1) Or not StringIsInt($addend2) Then
      Exit
   EndIf

   If StringLen($addend1) > StringLen($addend2) Then
      $Lenght = StringLen($addend1)
   Else
      $Lenght = StringLen($addend2)
   EndIf
   If $Lenght <= 3 Then 
      $Lenght = 3
   Else
      $Lenght = $Lenght + Mod($Lenght,3)
   EndIf
   
   While StringLen($Addend1) <> $Lenght
      $Addend1 = "0" & $Addend1
   Wend

   While StringLen($Addend2) <> $Lenght
      $Addend2 = "0" & $Addend2
   Wend
   
   For $c = 1 to $Lenght/3
      $SubTotal = Int(StringRight($addend1,3)) + Int(StringRight($addend2,3)) + $ToCarry
      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
      $Addend1 = StringTrimRight($Addend1,3)
      $Addend2 = StringTrimRight($Addend2,3)
      
   Next
   
   While StringInStr($sum,"0") = 1
      $Sum = StringTrimLeft($sum,1)
   Wend
   Msgbox(0,"",$sum)
   
EndFunc
Edited by ezzetabi

Share this post


Link to post
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 :ph34r: 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 :lol:

commenti

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0