将字符串转换为double的错误

时间:2017-10-22 11:34:44

标签: vb.net

我正在尝试在Visual Basic中将字符串转换为double,但我一直收到此错误:

  

System.InvalidCastException:'从字符串“48.00”转换为类型   'Double'无效。'

这是我的代码:

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是一个字符串)

1 个答案:

答案 0 :(得分:0)

在代码中尝试Double.Parse(hum)