Cint() , int(),round() , fix() 的区别与联系

前端之家收集整理的这篇文章主要介绍了Cint() , int(),round() , fix() 的区别与联系前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。


对比一下,印象会更深刻!


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

例如:Cint2.51=3Cint-2.51=-3


小于等于0.5的部分都舍去,不分正负

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

Cint(2.5)=2Cint(-2.5)=-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))


Int取到的是小于等于这个数的最大整数

例如:

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

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


       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))


Round确定好保留的位数后,后面的直接四舍五入

例如:

Round(2.459,2)=2.46

Round(2.454,2)=2.45

Round(-2.459)=-2.46

Round(-2.454,2)=-2.45


       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))


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

例如

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

Fix(-2.49)=-2Fix(-2.51)=-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

猜你在找的VB相关文章