I am trying to convert a pair of integers into a floating point variable (they should translate in a float value). I succesfully converted the pair of integers into a Long and i assumed that I was homefree by using the CDbl function. Unfortunately I am just getting the same number in the Double variable. The Long has a number like 1141187758 and this should translate in something like 530.xxx as a float. Anybody who can help me with this?
Asked
Active
Viewed 2,526 times
0
-
Not sure what you mean by this. A numerical value will be the same in any other numerical data type bar any rounding. Do you mean you are expecting it to look more like `1.14188888818776E+15` – Fred Oct 21 '13 at 09:26
-
Did you ask this same question on a forum 10 years ago or is this an assignment from some school? http://www.vbforums.com/showthread.php?259885-Convert-Integer-to-Float – Fred Oct 21 '13 at 09:30
-
this question represent exactly what im searching for, but in this forum i cannot get the response , what i want is converting an int = 1121991000 to a float in my example the float will be = 112.112, you can refer to his website for more example : http://www.binaryconvert.com/result_float.html?decimal=049049050046049049050 – Dani Pedrossa Oct 21 '13 at 09:37
1 Answers
2
Air code
Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" ( _
ByRef Destination As Any, _
ByRef Source As Any, _
ByVal Length As Long)
Function LongToFloat(ByVal l As Long) as Single
Dim f As Single
CopyMemory f, l, LenB(l)
LongToFloat = f
End Function
Adapted from this answer
-
"Air code" as in "air guitar": I mean I just typed it straight into the answer. It may not even compile. – MarkJ Oct 21 '13 at 18:32