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

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

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

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

        

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

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

在應(yīng)用程序中,因為數(shù)據(jù)的復(fù)雜性,經(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é)果為:" & 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

' 獲取不超過指定數(shù)值的非負(fù)隨機(jī)數(shù)
Sub 隨機(jī)數(shù)()
    Dim x As Double
    x = InputBox("請輸入數(shù)值:")
    MsgBox   Rnd(x) * x 
End Sub

' 獲取不超過指定數(shù)值的數(shù)隨機(jī)整數(shù)
Sub 隨機(jī)整數(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
移動訪問