string to double problem

stephankuba

Member
Licensed User
Longtime User
B4X:
'####################################
Dim d1 As Double
Dim d2 As Double 

If d_lati <> "" Then
   d1 = CDob(d_lati)
End If

If d_longi <> "" Then
   d2 = CDob(d_longi)
End If

Msgbox(d1 & "  " & d2,"sadf")

calc_uumkreis = CalcDistance(lat,lon,d1,d2)/1000

'###########################################

Sub CDob(o As Object) As Double
  Return Floor(o)
End Sub

Sub CalcDistance(lat1 As Double, lng1 As Double, lat2 As Double, lng2 As      Double) As Double
Dim l1, l2 As Location
Dim entfernung As Double 
    
l1.Initialize2(lat1, lng1)
l2.Initialize2(lat2, lng2)
    
entfernung = l1.DistanceTo(l2)* 1.609344
Return entfernung
End Sub

Hi, i want to convert a string to double. The variable d_lati(45.222) and d_longi(34.2222) are strings form a .txt file. Now i want to calc the distance between me and this gps positons.

The problem is 33.2222 gps is after convert to double 33

Maybe someone can help me, thank you.:sign0085:
PS: great forum
 

klaus

Expert
Licensed User
Longtime User
I don't understand your problem.
The Location.Initialize2(Latitude As String, Longitude As String) method needs two Strings and not two Doubles !
As your source data are Strings why do you want to convert them to Double ?

Best regards.
 
Upvote 0

stephankuba

Member
Licensed User
Longtime User
problem

B4X:
Sub CalcDistance(lat1 As Double, lng1 As Double, lat2 As Double, lng2 As      Double) As Double
Dim l1, l2 As Location
Dim entfernung As Double 

l1.Initialize2(lat1, lng1)
l2.Initialize2(lat2, lng2)

entfernung = l1.DistanceTo(l2)* 1.609344
Return entfernung
End Sub

first thank you for your help,

the problem is i want to calc the distance between two gps positions.
and the variable have to be in double.
I read the gps positions from a .txt file with textreader in a string variable now i want to calc the distance, but i have to convert the string in double.

The problem is if i convert it like this
B4X:
Sub CDob(o As Object) As Double
  Return Floor(o)
End Sub

it makes 43.1111 to 43

it's int not double
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
You should change your code to this:
B4X:
Sub CalcDistance(lat1 As String, lng1 As String, lat2 As String, lng2 As String) As Double
The conversion routine should look like this:
B4X:
Sub CDob(o As Object) As Double
    Dim d As Double
    d = o
    Return d
End Sub
You should add a check to verify if the object is a number.

Best regards.
 
Upvote 0
Top