mcorbeel Active Member Licensed User Longtime User Mar 14, 2023 #1 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?
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 Mar 14, 2023 #2 question has been asked and addressed before: https://www.b4x.com/android/forum/threads/bug-converting-string-to-long.133584/#content a couple remedies are suggested. you can also use a java object B4X: Dim t As String = "405006951190111400" Log("t=" & t) Dim i As Long = t Log("i=" & i) Dim jo As JavaObject jo.InitializeStatic("java.lang.Long") Log(jo.RunMethod("parseLong",Array( t ))) Log(jo.RunMethod("valueOf", Array(t))) Upvote 0
question has been asked and addressed before: https://www.b4x.com/android/forum/threads/bug-converting-string-to-long.133584/#content a couple remedies are suggested. you can also use a java object B4X: Dim t As String = "405006951190111400" Log("t=" & t) Dim i As Long = t Log("i=" & i) Dim jo As JavaObject jo.InitializeStatic("java.lang.Long") Log(jo.RunMethod("parseLong",Array( t ))) Log(jo.RunMethod("valueOf", Array(t)))
M Mahares Expert Licensed User Longtime User Mar 14, 2023 #3 Post #2 is correct. But another way is to use BigNumber library by aGraham: Code: 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
Post #2 is correct. But another way is to use BigNumber library by aGraham: Code: 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
mcorbeel Active Member Licensed User Longtime User Mar 18, 2023 #4 Thanks everyone. Will look into it... Upvote 0