|
本帖最后由 一指禅 于 2012-5-9 22:31 编辑
一位网友做的函数大家测试下!
Function CRound(C As String, D As Integer)
Dim dotlocation As Integer '定义小数点位置变量
dotlocation = InStr(C, ".") '确定小数点的位置
If Mid(C, dotlocation + D + 1, 1) = 5 Then '判断小数点后第d+1位是否为5
If Len(C) <= dotlocation + D + 1 And Mid(C, dotlocation + D, 1) Mod 2 = 0 Then
CRound = --Left(C, dotlocation + D)
Else
CRound = Round(C, D) '为5且5后没有数以及5前一位为偶数,用left函数修约,否则用round()函数修约
End If
Else
CRound = Round(C, D) ''不为5,直接用round()函数修约
End If
End Function
http://club.excelhome.net/forum.php?mod=viewthread&tid=800269 |
|