Android Question Solved - String to long integer odd issue

padvou

Active Member
Licensed User
Longtime User
Hi!
Consider this string: 637406139915958403 and this: 637406139915958402
using this sub:
B4X:
Sub CI(str As String) As Long
    If IsNumber(str) Then
    Try
        Dim ret As Long
        ret = str
        Return ret
    Catch
        Return 0
    End Try
    Else
        Return 0
    End If
End Sub
returns 637406139915958400 in both strings.
Why??:eek:
 

OliverA

Expert
Licensed User
Longtime User
Almost looks like the values are first converted to a Double and then to an Int a Long
B4X:
    Dim one As String = "637406139915958402"
    Dim two As String = "637406139915958403"
    Dim double1 As Double = one
    Dim double2 As Double = two
    Log($"$18{double1}"$)
    Log($"$18{double2}"$)
Output:
double1: 637,406,139,915,958,400
double2: 637,406,139,915,958,400
 
Upvote 0

OliverA

Expert
Licensed User
Longtime User
Confirmed
B4X:
    Dim one As String = "637406139915958402"
    Dim long1 As Long = one
The resulting Java code fo the long1 assignment is
Java:
_long1 = (long)(Double.parseDouble(_one));
 
Upvote 0

OliverA

Expert
Licensed User
Longtime User
Upvote 0
Top