如果您需要自己的算法,请尝试以下操作:
WSH.Echo CustomRound(-123456.7) '-123457
WSH.Echo CustomRound(-123456.5) '-123456
WSH.Echo CustomRound(-123456.3) '-123456
WSH.Echo CustomRound(123456.7) '123457
WSH.Echo CustomRound(123456.5) '123457
WSH.Echo CustomRound(123456.3) '123456
Function CustomRound(nValue)
CustomRound = Int(nValue + 0.5)
End Function
或者...
WSH.Echo CustomRound2(-123456.7) '-123457
WSH.Echo CustomRound2(-123456.5) '-123457
WSH.Echo CustomRound2(-123456.3) '-123456
WSH.Echo CustomRound2(123456.7) '123457
WSH.Echo CustomRound2(123456.5) '123457
WSH.Echo CustomRound2(123456.3) '123456
Function CustomRound2(nValue)
CustomRound2 = Sgn(nValue) * Int(Abs(nValue) + 0.5)
End Function
嗯......还有一个想法:)
Function RoundFrm(nValue)
RoundFrm = Null
If IsEmpty(nValue) Or _
Not IsNumeric(nValue) Then Exit Function
RoundFrm = FormatNumber(nValue, 0)
End Function
并且使用上面的想法可以使功能更完整,例如...
Function RoundEx(nValue)
Select Case VarType(nValue)
Case vbInteger, vbLong
RoundEx = nValue
Case vbSingle
RoundEx = CSng(FormatNumber(nValue, 0))
Case vbDouble
RoundEx = CDbl(FormatNumber(nValue, 0))
Case vbCurrency
RoundEx = CCur(FormatNumber(nValue, 0))
Case Else: RoundEx = Null
End Select
End Function