The function that you could use to convert a long number to double is : cDbl
Example source code:
Dim dblMyNumber As Double Dim lngMyNumber As Long
lngMyNumber = 1002992
dblMyNumber = CDbl(lngMyNumber)
Thus lngMyNumber was converted to a double using CDbl. The output double variable is dblMyNumber.
Now, to convert a Double to a long, you need cLng function. cLng (Convert to Long) is used like in the following example:
Example source code:
Dim dblMyNumber As Double Dim lngMyNumber As Long
dblMyNumber = 1002992
lngMyNumber = CLng(dblMyNumber)
So dblMyNumber was converted to a Long using CLng. The output double variable is lngMyNumber.
NOTICE: The Long data type is a 32-bit number It ranges from -2,147,483,648 to 2,147,483,647. Long variables can only contain non-fractional integer values.
The Double data type is a 64-bit floating point number used when high accuracy is needed. These variables can range from -1.79769313486232e308 to -4.94065645841247e-324 for negative values and from 4.94065645841247e-324 to 1.79769313486232e308 for positive values.
This means that you might face overflow issues because Double has the double size than Long datatype.
Take a look at the following code:
Dim dblMyNumber As Double Dim lngMyNumber As Long
dblMyNumber = 3147483647#
lngMyNumber = CLng(dblMyNumber)
|
Labels: cdbl, clng, datatype, double, floating point, long, overflow |