[erlang-questions] float_to_binary?

Serge Aleynikov saleyn@REDACTED
Tue Jan 27 14:00:35 CET 2009


1> Float = 1.0.
1.0
2> <<Float/float>>.
<<63,240,0,0,0,0,0,0>>

If you need that float to be encoded in the external format, uou can use 
term_to_binary(Float, [{minor_version, 1}]) for IEEE 754 encoding:

3> term_to_binary(Float, [{minor_version, 1}]).
<<131,70,63,240,0,0,0,0,0,0>>

Serge

Steve Davis wrote:
> I'm probably being dumb, but I am stuck...
> 
> to_binary(X) when is_integer(X) -> <<X>>;
> to_binary(X) when is_float(X) -> ??.
> 
> ...btw attempting to use erlang:float_to_binary(X, 64) turned out to be 
> a very bad idea (computer just went POP!).
> 
> Thanks for any assistance!
> /s
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://www.erlang.org/mailman/listinfo/erlang-questions
> 




More information about the erlang-questions mailing list