office交流網(wǎng)--QQ交流群號(hào)及微信交流群

Access培訓(xùn)群:792054000         Excel免費(fèi)交流群群:686050929          Outlook交流群:221378704    

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

微信交流群(請(qǐng)用微信掃碼)

        

Access向上取整的類似Excel的Ceiling函數(shù)

2019-08-06 21:25:00
zstmtony
原創(chuàng)
4537

在Excel中有自帶的Ceiling函數(shù)可實(shí)現(xiàn)向上取整,但Access,沒有,需要自己寫一下

以下有2個(gè)函數(shù)的寫法,可參考:


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 (默認(rèn)值為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

分享
文章分類
聯(lián)系我們
聯(lián)系人: 王先生
Email: 18449932@qq.com
QQ: 18449932
微博: officecn01
移動(dòng)訪問