贾琳 一名系统架构师的征途

shan9liang==善久良==永远保持善良……

比较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

阅读更多
版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/shan9liang/article/details/6139914
文章标签: list command
个人分类: 编程语言
上一篇VB全局对象
下一篇举例说明常用字符串处理函数
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

关闭
关闭