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

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

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

微信交流群(請用微信掃碼)

        

access數(shù)據(jù)處理函數(shù)(四捨五入到整數(shù),指定隨機整數(shù))

2020-11-24 08:00:00
tmtony8
原創(chuàng)
6222

在應(yīng)用程序中,因爲(wèi)數(shù)據(jù)的複雜性,經(jīng)常需要對數(shù)據(jù)進(jìn)行處理

access中提供瞭很多數(shù)據(jù)處理的函數(shù),比如取整,取正數(shù)等。下麵分享幾箇常用的的數(shù)據(jù)處理函數(shù)

 

' 四捨五入到整數(shù)
Sub 四捨五入()
    Dim x As Double
    x = InputBox("請輸入數(shù)值:")
    MsgBox  CInt(x) 
End Sub


' 將數(shù)值四捨五入到指定位數(shù)
Sub 定位四捨五入()
    Dim x As Double
    Dim n As Integer
    x = InputBox("請輸入數(shù)值:")
    n = InputBox("請輸入進(jìn)行四捨五入的位數(shù):")
    MsgBox  "保留" & n & "位小數(shù)的結(jié)果爲(wèi):" & Round(x, n) 
End Sub

 
' 對輸入數(shù)值取整,負(fù)數(shù)取小
Sub 取整1()
    Dim x As Double
    x = InputBox("請輸入數(shù)值:")
    MsgBox   Int(x) 
End Sub

' 對輸入的數(shù)值取整,負(fù)數(shù)取大
Sub 取整2()
    Dim x As Double
    x = InputBox("請輸入數(shù)值:")
    MsgBox   Fix(x) 
End Sub

' 穫?cè)〔怀^指定數(shù)值的非負(fù)隨機數(shù)
Sub 隨機數(shù)()
    Dim x As Double
    x = InputBox("請輸入數(shù)值:")
    MsgBox   Rnd(x) * x 
End Sub

' 穫?cè)〔怀^指定數(shù)值的數(shù)隨機整數(shù)
Sub 隨機整數(shù)()
    Dim x As Double
    x = InputBox("請輸入數(shù)值:")
    MsgBox  Int(Rnd(x) * x)
End Sub

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