Android Question Convert string to long issue

mcorbeel

Active Member
Licensed User
Longtime User
I am trying to convert a string of digits to a long value. On B4i it works fine, but on B4X it does not.
B4X:
Dim t As String = "405006951190111400"
Log("t=" & t)
   
Dim i As Long = t
Log("i=" & i)

This gives:
t=405006951190111400
i=405006951190111424

Why is the i value different? How can I fix this?
 

drgottjr

Expert
Licensed User
Longtime User
Upvote 0

Mahares

Expert
Licensed User
Longtime User
Post #2 is correct. But another way is to use BigNumber library by aGraham:
B4X:
Dim t As String = "405006951190111400"
    Log(t)
    Dim i As BigInteger   'need to download the B4A BigNumber library by aGraham. Needs to be in the B4A additional library folder
    i.Initialize(t)    '405006951190111400
    Log(i)    '405006951190111400
 
Upvote 1
Top