[erlang-questions] float_to_binary?

Gleb Peregud gleber.p@REDACTED
Tue Jan 27 13:52:10 CET 2009


to_binary(X) when is_integer(X) -> <<X>>; %% it will give you 1-byte
binary, truncating integer to range 0..255 (i.e. byte)
to_binary(X) when is_float(X) -> <<X/float>>. %% it will give you a
8-bytes binary (i.e. 64-bits float)

On Tue, Jan 27, 2009 at 1:41 PM, Steve Davis
<steven.charles.davis@REDACTED> 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
>



-- 
Gleb Peregud
http://gleber.pl/

Every minute is to be grasped.
Time waits for nobody.
-- Inscription on a Zen Gong



More information about the erlang-questions mailing list