装作自己厉害到能写博客了…
真的只是个水贴…做的比我好的不是大有人在了 而是不计其数了
最简单的 四舍五入到个位: Iris= Int(Lily + 0.5)
推广到 四舍五入到10^P位: Iris = Int(Lily * 10 ^ (-P) + 0.5) * 10 ^ P
…但是为什么不用Round(expression [,numdecimalplaces]) 呢
再推广到 n-1舍n入到10^P位 ,写成你们拿去就能用的函数好了:
Public Function Miaow(ByVal Lily As Double, Optional ByVal P As Integer = 0, Optional ByVal n As Byte = 5) As Double
If n < 1 Or n > 9 Then
MsgBox "数学不好的Iris并不能算出来呢"
Exit Function
End If
Miaow = Int(Lily * 10 ^ (-P) + 0.1 * n) * 10 ^ P ‘★
End Function
有★的那句才是重点…
以及 n-1舍n+1入n留I到10^P位 ,I = 0 时就是上式 ,I = 1 时留单 ,I = 2 时留双:
Public Function Meow(ByVal Lily As Double, Optional ByVal P As Integer = 0, Optional ByVal n As Byte = 5, Optional ByVal I As Byte = 0) As Double
If n < 1 Or n > 9 Or I > 2 Then
MsgBox "数学不好的Iris并不能算出来呢"