我正在尝试在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
是一个字符串)
答案 0 :(得分:0)
在代码中尝试Double.Parse(hum)