比較Cint() , int() , fix() ,round()的區別

來源:互聯網
上載者:User

 

Cint 小數部分超過0.5的部分都進位,不分正負

例如:Cint(2.51)=3  Cint(-2.51)=-3

        

         小於等於0.5的部分都捨去,不分正負

例如:Cint(2.49)=2 Cint(-2.49)=-2

             Cint(2.5)=2  Cint(-2.5)=-2

 

Int 取到的是小於這個數的最大整數

例如:

Int(2.49)=2   Int(2.50)=2  Int(2.51)=2

Int(-2.49)=-3   Int(-2.50)=-3  Int(-2.51)=-3

 

Round 確定好保留的位元後,後面的直接四捨五入

例如:

Round(2.459,2)=2.46

Round(2.454,2)=2.45

Round(-2.459)=-2.46

Round(-2.454,2)=-2.45   

 

Fix 省略小數位,即直接截走小數位

例如

Fix(2.51)=2    Fix(2.49)=2

Fix(-2.49)=-2      Fix(-2.51)=-2

 

在實際操作中驗證:

Private Sub Command1_Click()

       List1.AddItem "Cint(2.49)=" & CStr(CInt(2.49))

       List1.AddItem "Cint(-2.49)=" & CStr(CInt(-2.49))

       List1.AddItem "Cint(2.50)=" & CStr(CInt(2.5))

       List1.AddItem "Cint(-2.50)=" & CStr(CInt(-2.5))

       List1.AddItem "Cint(2.12)=" & CStr(CInt(2.12))

       List1.AddItem "Cint(-2.12)=" & CStr(CInt(-2.12))

       List1.AddItem "Cint(2.51)=" & CStr(CInt(2.51))

       List1.AddItem "Cint(-2.51)=" & CStr(CInt(-2.51))

    

       List1.AddItem " "

      

       List1.AddItem "Int(2.49)=" & CStr(Int(2.49))

       List1.AddItem "Int(-2.49)=" & CStr(Int(-2.49))

       List1.AddItem "Int(2.50)=" & CStr(Int(2.5))

       List1.AddItem "Int(-2.50)=" & CStr(Int(-2.5))

       List1.AddItem "Int(2.12)=" & CStr(Int(2.12))

       List1.AddItem "Int(-2.12)=" & CStr(Int(-2.12))

       List1.AddItem "Int(2.51)=" & CStr(Int(2.51))

       List1.AddItem "Int(-2.51)=" & CStr(Int(-2.51))

       List1.AddItem "Int(-0.51)=" & CStr(Int(-0.51))

       List1.AddItem "Int(0.51)=" & CStr(Int(0.51))

      

       List1.AddItem " "

      

       List1.AddItem "Round(2.459,2)=" & CStr(Round(2.459, 2))

       List1.AddItem "Round(-2.459,2)=" & CStr(Round(-2.459, 2))

       List1.AddItem "Round(2.454,2)=" & CStr(Round(2.454, 2))

       List1.AddItem "Round(-2.454,2)=" & CStr(Round(-2.454, 2))

      

       List1.AddItem " "

      

       List1.AddItem "fix(2.45)=" & CStr(Fix(2.45))

       List1.AddItem "fix(2.51)=" & CStr(Fix(2.51))

       List1.AddItem "fix(-2.49)=" & CStr(Fix(-2.49))

       List1.AddItem "fix(-2.51)=" & CStr(Fix(-2.51))

End Sub

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.