BitsAndBytes Active Member Licensed User Jun 25, 2017 #1 I have a problem i want to convert this string "999,999.00" to double variable but this function returns me zero Code: Copy 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
I have a problem i want to convert this string "999,999.00" to double variable but this function returns me zero Code: Copy 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
mangojack Expert Licensed User Longtime User Jun 25, 2017 #2 Code: Copy Sub returnDouble(strValue As String) As Double If IsNumber(strVal) Then ' @@ strValue vs strVal Upvote 0
Code: Copy Sub returnDouble(strValue As String) As Double If IsNumber(strVal) Then ' @@ strValue vs strVal
M Mahares Expert Licensed User Longtime User Jun 25, 2017 #3 In addition to @mangojack tip, you need to remove the comma from the following line: textViewValue = "999,999.00" or use the following: Code: Copy 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: Code: Copy 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 Last edited: Jun 25, 2017 Upvote 0
In addition to @mangojack tip, you need to remove the comma from the following line: textViewValue = "999,999.00" or use the following: Code: Copy 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: Code: Copy 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
Erel B4X founder Staff member Licensed User Longtime User Jun 25, 2017 #4 Tip: You can write: Code: Copy Dim doubleValue As Double = strValue Upvote 0