WriteFloat stream,float#
Parameters
|
stream - a file stream opened for writing, or a TCP stream float# - floating point value to write |
Description
|
Writes a floating point value to a file or stream. A float occupies 4 bytes and round-trips exactly through ReadFloat - the way to store positions, angles and other fractional values in a binary save without the precision loss of printing them as text. See also: ReadFloat, WriteInt, WriteString. |
Example
; WriteFloat Example ; ------------------ ; WriteFloat stores a 4-byte single-precision float file=WriteFile("demo_floats.dat") WriteFloat file,10.5 WriteFloat file,-0.125 WriteFloat file,365.25 CloseFile file Print "Wrote 3 floats - demo_floats.dat is "+FileSize("demo_floats.dat")+" bytes (3 x 4)" ; Read them back to prove the round trip file=ReadFile("demo_floats.dat") a#=ReadFloat(file) b#=ReadFloat(file) c#=ReadFloat(file) CloseFile file Print "Read back: "+a+", "+b+", "+c ; Clean up the demo file DeleteFile "demo_floats.dat" Print "Deleted demo_floats.dat" Print "" Print "Press any key to close the example" WaitKey End
Index