Float to binary

Bob Cowdery <>
Mon Mar 21 15:09:29 CET 2011

If I have a float value. This happens to be a frequency in MHz which I
need to convert to a 32 bit integer big-endian format in Hz how do I get
the float into a suitable format.  The following converts the term into
an external term format which is no good for the binary comprehension.
How can I convert the value into a binary without getting the external
format header or is there a different way to approach this. It seems to
know that F is 1.0 as it let me rebind it.

1> F=1.0.
2> B = term_to_binary(F, [{minor_version, 1}]).
3> << <<(round(F*1000000)):32/big>> || <<F:64/float>> <=
<<63,240,0,0,0,0,0,0>> >>.

Thanks once again for any help.


More information about the erlang-questions mailing list