office交流网--QQ交流群号

Access培训群:792054000         Excel免费交流群群:686050929          Outlook交流群:221378704    

Word交流群:218156588             PPT交流群:324131555

Access向上取整的类似Excel的Ceiling函数

2019-08-06 21:25:00
zstmtony
原创
4381

在Excel中有自带的Ceiling函数可实现向上取整,但Access,没有,需要自己写一下

以下有2个函数的写法,可参考:


Public Function Ceiling(ByVal X As Double, Optional ByVal Factor As Double = 1) As Double
  ' X is the value you want to round
  ' Factor is the optional multiple to which you want to round, defaulting to 1 (默认值为0)
  Ceiling = (Int(X / Factor) - (X / Factor - Int(X / Factor) > 0)) * Factor
End Function



Public Function Ceiling(RoundValue As Currency) As Currency
    Dim TheValue As Currency
    TheValue = RoundValue
    Select Case TheValue - Int(TheValue)
        Case Is <= 0.25
            Ceiling = Int(TheValue)
        Case Is >= 0.5
            Ceiling = Int(TheValue) + 1
        Case Is >= 0.26
            Ceiling = Int(TheValue) + 0.5
    End Select
End Function

分享