


CDbl( expression )
CInt( expression )
CLng( expression )
CSng( expression )
CStr( expression )
CVar( expression )
The following table shows which data type is returned by each data type
conversion function.
Data Type Conversion Functions
| Function
| From
| To
|
| CCur
| Any valid expression
| Currency
|
| CDbl
| Any valid expression
| Double
|
| CInt
| Any valid expression
| Integer
|
| CLng
| Any valid expression
| Long
|
| CSng
| Any valid expression
| Single
|
| CStr
| Any valid expression
| String
|
| CVar
| Any valid expression
| Variant
|
Because CInt and CLng convert expressions to integers, you can use these functions to round fractional numbers.
Tip All data type conversion functions can provide self-documenting code that indicates that the result of a calculation should be expressed as a particular data type rather than the default data type of the result.
For the CCur, CInt, CLng, and CSng functions, if expression lies outside the acceptable range, a run-time error occurs and a message is displayed unless it is trapped in error-handling code.
Note CInt differs from the Fix and Int functions, which truncate, rather than round, the fractional part of a number. For a demonstration of the differences between Int and Fix, see the example for Int. When the fractional part is exactly 0.5, the CInt function always rounds it to the nearest even number. For example, 0.5 rounds to 0, and 1.5 rounds to 2.