Google
 
Web undim.blogspot.com
Visual Basic developer's world

Monday, March 01, 2010
How to convert a long number to double and vice versa
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: , , , , , ,


posted by Admin @ 2:30 AM   12 comments

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 
About Me

Name: Admin
Home: The NeverLands
About Me: A source code wonderer since the early 80s with my first ZX81 by Sinclair, home computer.
See my complete profile
Previous Post
Archives
Must-See Places
ΣΚΛΗΡΥΝΣΗ ΚΑΤΑ ΠΛΑΚΑΣ - ΕΓΚΕΦΑΛΟΣ - ΕΓΚΕΦΑΛΟΓΡΑΦΗΜΑ - ΑΝΟΙΑ - ΝΕΥΡΟΛΟΓΟΣ - ΨΥΧΙΑΤΡΟΣ - ΛΟΙΜΩΔΗΣ ΜΟΝΟΠΥΡΗΝΩΣΗ - ΠΑΡΚΙΝΣΟΝ - ΑΓΧΟΣ - ΚΑΤΑΘΛΙΨΗ - ALZHEIMER - EPSTEIN BARR eurolife
e-LaUgHs :-)
Template By
Free Blogger templates