Using CSng function in VB
CSng is a function that is used to convert a data to Single data type. Unlike CDbl which forces double-precision, CSng is only a single-precision data type. See the example shown below on how CSng works.
Dim MyData1, MyData2 As Double '--- Declares Variable
Dim Output1, Output2 As Single
MyData1 = 43.982865935 '--- Initialize data
MyData2 = 853719.4588613
Output1 = CSng(MyData1) '--- Convert MyData1 into Single data type
Output2 = CSng(MyData2) '--- Convert MyData1 into Single data type
MsgBox(Output1) '--- Output1 is 43.98286
MsgBox(Output2) '--- Output2 is 853719.4
As can be seen in the result above, only a fixed number of digits is shown in the output even though the original figures has more. Thus, that shows how CSng is applied in Visual Basic programming.
See Also CType Functions
Subscribe to:
Post Comments (Atom)

0 comments
Post a Comment