|
楼主 |
发表于 2014-2-2 10:37
|
显示全部楼层
呵呵,闲来头脑清醒,解决了进位的几个问题。现把代码帖出来,大家检查下,还望不吝赐教!
Option Explicit
Public Function qw(num As Double, Optional ws As Integer = 0) '去尾法
qw = Int(num * 10 ^ ws) / 10 ^ ws
End Function
Public Function s4r5(num As Double, Optional ws As Integer = 0) '四舍五入
s4r5 = Int(num * 10 ^ ws + 0.5) / 10 ^ ws
End Function
Public Function s4r6ou5(num As Double, Optional ws As Integer = 0) '四舍六入五成双
Dim wszgw%, blzdw% '尾数最高位,保留最低位
wszgw = Right(Int(num * 10 ^ (ws + 1)), 1)
blzdw = Right(Int(num * 10 ^ (ws)), 1)
If wszgw <= 4 Then
s4r6ou5 = Int(num * 10 ^ ws) / 10 ^ ws
ElseIf wszgw >= 6 Then
s4r6ou5 = Int(num * 10 ^ ws + 1) / 10 ^ ws
ElseIf blzdw Mod 2 = 0 Then
s4r6ou5 = Int(num * 10 ^ ws) / 10 ^ ws
Else
s4r6ou5 = Int(num * 10 ^ ws + 1) / 10 ^ ws
End If
End Function
Public Function s5r6(num As Double, Optional ws As Integer = 0) '五舍六入
s5r6 = Int(num * 10 ^ ws + 0.4) / 10 ^ ws
End Function
Public Function jy(num As Double, Optional ws As Integer = 0) '进一法
If Int(num * 10 ^ ws) = num * 10 ^ ws Then
jy = Int(num * 10 ^ ws) / 10 ^ ws
Else
jy = Int(num * 10 ^ ws + 1) / 10 ^ ws
End If
End Function
|
|