I have a problem i want to convert this string "999,999.00" to double variable but this function returns me zero
B4X:
dim doubleValue as double
textViewValue = "999,999.00"
doubleValue = returnDouble (textViewValue)
Sub returnDouble(strValue As String) As Double
If IsNumber(strVal) Then
Dim doubleValue As Double : doubleValue = strVal
Return doubleValue
Else
Return 0
End If
End Sub
In addition to @mangojack tip, you need to remove the comma from the following line:
textViewValue = "999,999.00"
or use the following:
B4X:
Sub returnDouble(strValue As String) As Double
If IsNumber(strValue.Replace(",","")) Then
Dim doubleValue As Double : doubleValue = strValue
Return doubleValue
Else
Return 0
End If
End Sub
EDIT: the following looks better:
B4X:
Sub returnDouble(strValue As String) As Double
strValue=strValue.Replace(",","")
If IsNumber(strValue) Then
Dim doubleValue As Double : doubleValue = strValue
Return doubleValue
Else
Return 0
End If
End Sub