下面的功能用于计算用户对问题的答案。
如果用户尚未参加考试,请显示一条消息,表明用户尚未参加考试。
如果用户的答案在0%到75%之间,请告知用户他/她不满足最低要求。
如果用户的分数大于75%,则表明用户已通过。
问题是,如果用户的分数为0,则用户会收到一条消息,表明他/她没有参加考试,这是错误的。
知道我该如何纠正吗?
在此先多谢
Public Function getStatus(ByVal value As Object) As String
Dim myRow As FormViewRow = scoreGridView.Row
Dim Message As String = ""
Dim lbscore As Label = DirectCast(myRow.FindControl("PercentLabel"), Label)
If Decimal.Parse(value) >= 0 AndAlso Decimal.Parse(value) < 75 Then
Message = "<span style='color:red;font-weight:bold'>Your score does not meet minimum requirement</span>"
ElseIf Decimal.Parse(value) >= 75 Then
Message = "<span style='color:green;font-weight:bold'>Congratulations you have passed the test!</span>"
Else
Message = "You have not yet taken the test for this survey"
End If
Return Message
End Function
最佳答案
使用d
文字后缀作为您的值,以确保将它们作为Decimal
类型进行比较,如下所示:
Public Function getStatus(ByVal value As Object) As String
Dim myRow As FormViewRow = scoreGridView.Row
Dim Message As String = ""
Dim lbscore As Label = DirectCast(myRow.FindControl("PercentLabel"), Label)
If Decimal.Parse(value) >= 0d AndAlso Decimal.Parse(value) < 75d Then
Message = "<span style='color:red;font-weight:bold'>Your score does not meet minimum requirement</span>"
ElseIf Decimal.Parse(value) >= 75d Then
Message = "<span style='color:green;font-weight:bold'>Congratulations you have passed the test!</span>"
Else
Message = "You have not yet taken the test for this survey"
End If
Return Message
End Function
另外,为了检查零(十进制),可以使用
Decimal.Zero
,如下所示:If Decimal.Parse(value) >= Decimal.Zero AndAlso Decimal.Parse(value) < 75d Then
关于asp.net - 您知道我如何获得此功能以产生正确的结果吗?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/18767935/