Dani Pedrossa
Dani Pedrossa

Reputation: 39

how to convert int to float in VB6

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?

Upvotes: 0

Views: 2996

Answers (1)

MarkJ
MarkJ

Reputation: 30408

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

Upvotes: 2

Related Questions