比较Cint() , int() , fix() ,round()的区别

 

Cint 小数部分超过0.5的部分都进位,不分正负

例如:Cint2.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

posted @ 2011-01-14 18:13  spring高手  阅读(2910)  评论(0编辑  收藏  举报