office交流網--QQ交流群號

Access培訓群:792054000         Excel免費交流群群:686050929          Outlook交流群:221378704    

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

Access曏上取整的類似Excel的Ceiling函數

2019-08-06 21:25:00
zstmtony
原創
922

在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

分享