-1

I'm trying to convert a string to double in Visual Basic, but I keep getting this error:

System.InvalidCastException: 'Conversion from string "48.00 " to type 'Double' is not valid.'

This is my code:

Private Sub ratingupdater_Tick(sender As Object, e As EventArgs) Handles ratingupdater.Tick
        If hum = "" Then
            Return
        End If
        If temp = "" Then
            Return
        End If
        If hum = "NAN" Then
            Return
        End If
        If temp = "NAN" Then
            Return
        End If
        'humidity Rating
        Dim tempolary As Double
        tempolary = CDbl(hum)
        tempval.Text = tempolary
        If tempolary > 75 Then
            humrating.Text = "High"
            humrating.ForeColor = Color.Red
        End If
        If tempolary >= 65 And tempolary < 75 Then
            humrating.Text = "Mid"
            humrating.ForeColor = Color.Orange
        End If
        If tempolary < 65 Then
            humrating.Text = "Low"
            humrating.ForeColor = Color.Green
        End If
        tempolary = 0
    End Sub

(hum is a string)

1 Answers1

0

Try Double.Parse(hum) in your code

Rahul Cv
  • 725
  • 5
  • 12