The Data Type Conversion FunctionsTable 14.1 describes the data type conversion functions, denoted by their initial letter C (for convert). Each function converts its argument from one data type to another. Table 14.1 The Data Type Conversion Functions
Unlike Int() and Fix(), CInt() returns the closest rounded integer to the argument. Look at the remarks to the right of each of the following statements to see what's stored in each variable: cA1 = CInt(8.5) ' Stores an 8 in cA2 cA2 = CInt(8.5001) ' Stores a 9 in cA3 For negative numbers, CInt() also rounds to the closest whole integer. The following code declares a variable of four different data types and then converts each argument to those data types. Remember that you also can pass these functions expressions that produce numeric results so that you can control the data types of your calculated results before storing them in a field or variable. vVar1 = CCur(123) ' Converts 123 to currency data type vVar2 = CDbl(123) ' Converts 123 to double-precision data type vVar3 = CSng(123) ' Converts 123 to single-precision data type vVar4 = CVar(123) ' Converts 123 to the variant data type |
|||||||||||||||||||||||||
![]() |
![]() |
|||