Converting single precision float to a 4 byte string
Posted on 2003-03-01
I need a function to convert a single precision floating point into a 4 byte string (so that I can story it into a binary file).
I have tried to do this by creating the function below
Public Declare Sub RtlMoveMemory Lib "kernel32" (ByVal hpvDest As Long, ByVal hpvSource As Long, ByVal cbCopy As Long)
Function floattostring(byval tFloat as single) as String
dim sBuffer As String
sBuffer = String(4, vbNullChar)
RtlMoveMemory StrPtr(sBuffer), VarPtr(tFloat), 4
floattostring = sBuffer
however it doesn't seem to work (the string returned is always the 4 bytes "3F 3F 00 00").
Does anyone know a simple way I could convert this (either using memory copy/read api or actually converting it using an vb function)