这是我的测试代码:
Dim testSingle As Single = 7.2
Dim testSingleF As Single = 7.2F
Dim testDouble As Double = 7.2
If testSingle = testDouble Then ' this is false
Label1.Text = "true"
Else
Label1.Text = "false"
End If
If testSingleF = testDouble Then ' this is false
Label2.Text = "true"
Else
Label2.Text = "false"
End If
If testSingle = 7.2F Then ' this is true
Label3.Text = "true"
Else
Label3.Text = "false"
End If
Run Code Online (Sandbox Code Playgroud)
正如您在我的评论中所看到的,前两个陈述是错误的,第三个是真的.这是为什么?精度应该无关紧要,因为它的数量很少.
这里发生了什么?
vb.net ×1