|
这个拿去改一改
Public Function MyRound(x As Double, Y As Integer)
Dim i As Integer, Dbla, Dblb, Dblc As Double, MyR As Long
Rem 示例:MyRound(5.25,1) 返回5.2
Rem >0.5进位、=0.5时逢单才进位
i = 1
If x < 0 Then i = -1
Dbla = Abs(x)
Dblc = Int(Dbla * 10 ^ Y)
Dblb = Dbla * 10 ^ Y - Dblc
If Dblb < 0.5 Then
MyR = Dblc
ElseIf Dblb = 0.5 Then '0.5 可另改成你想要的进位标准
If Right(Dblc, 1) Mod 2 = 1 Then
MyR = Dblc + 1
Else
MyR = Dblc
End If
ElseIf Dblb > 0.5 Then
MyR = Dblc + 1
End If
MyRound = MyR * i / 10 ^ Y
End Function
|
|