[erlang-questions] binary_to_float: <<"2e-1">> versus <<"2.0e-1">>

Peter Morgan peter.james.morgan@REDACTED
Fri Jan 30 09:25:16 CET 2015


I am parsing output from another system, where numbers arrive in a variety
of forms which are out of my control. This one has caught me out recently:

1> binary_to_float(<<"2e-1">>).

** exception error: bad argument

     in function  binary_to_float/1

        called as binary_to_float(<<"2e-1">>)


Whereas:

2> binary_to_float(<<"2.0e-1">>).

0.2


On:

erl -version

Erlang (SMP,ASYNC_THREADS,HIPE) (BEAM) emulator version 6.3


Any good reason why in binary_to_float with a scientific notation the
coefficient must be a float?

I'm now pattern matching this case before passing a modified coefficient as
a floating point before passing it to binary_to_float.

Thanks,
Peter.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20150130/56c225a4/attachment.htm>


More information about the erlang-questions mailing list