CSDN博客

img yinweihong

四舍五入

发表于2004/9/27 1:37:00  759人阅读

Public Function RoundF(Number, Optional NumOfDigits As Long) As Double
    If Not IsNumeric(Number) Then Exit Function
    Dim iPos As Long
    iPos = InStr(Number, ".")
    Dim dbDesimalPart As Long
    Dim dbRoundPart As Long
    If iPos > 0 Then
        dbDesimalPart = Mid(Number, iPos + 1)
    End If
    If NumOfDigits < Len(CStr(dbDesimalPart)) Then
        dbRoundPart = Mid(dbDesimalPart, NumOfDigits + 1, 1)
    End If
    If dbRoundPart > 4 Then
        dbDesimalPart = Left(dbDesimalPart, NumOfDigits) + 1
    Else
        dbDesimalPart = Left(dbDesimalPart, NumOfDigits)
    End If
    RoundF = Val(Int(Number) & "." & dbDesimalPart)
End Function
阅读全文
0 0

相关文章推荐

img
取 消
img