CDbl Function

Converts any numeric type or String to a Double value.

...CDbl ( expression )

Prerequisites

None

Parameters

expression

A required numeric or string expression.  The numeric expression can yield any type of result, i.e. Boolean, Byte, Double, Integer, Short or Single.

Remarks

The conversion operators are a group of functions that convert an expression that evaluates to any numeric or string type into a specified data type.  The conversion tests that the converted value falls within the proper range of values for the returned data type.  If the converted value is out of range, and error is generated.

As opposed to the Int and Fix functions, the conversion functions convert real numbers to integers by rounding rather than truncation.

The table below summarizes all of the conversion functions.

 
Function Returned Data Type Range of Valid Expression Values

CBool

Boolean

Any 0 or non-zero value

CByte

Byte

0 to 255

CDbl

Double

-1.79769313486231E+308 to
-4.94065645841247E-324 for negative values;
4.94065645841247E-324 to
1.79769313486231E+308 for positive values.

CInt

Integer

-2,147,483,648 to 2,147,483,647

CShort

Short

-32768 to 32767

CSng

Single

-3.402823E+38 to -1.401298E-45 for negative values; 1.401298E-45 to 3.402823E+38 for positive values.

CStr

String

Any valid Double value

Hex

String

Any valid Integer value

 

Examples

Dim s_val As Single
s_val = CInt(3.14159) ' Sets s_val equal to 3
s_val = CByte(300) ' WILL GENERATE AN ERROR

See Also

Functions | Fix Function | Int Function