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

Peter Morgan peter.james.morgan@REDACTED
Fri Jan 30 11:17:52 CET 2015


Ah, OK - good to know. I'm using the following as a result:


btof(<<Coefficient:8, "e-", Remainder/binary>>) when Coefficient >= $0
andalso Coefficient =< $9 ->
    binary_to_float(<<Coefficient:8, ".0e-", Remainder/binary>>);
btof(Float) ->
    binary_to_float(Float).




Thanks,
Peter.

On 30 January 2015 at 10:03, Anthony Ramine <n.oxyde@REDACTED> wrote:

> Le 30 janv. 2015 à 09:25, Peter Morgan <peter.james.morgan@REDACTED> a
> écrit :
>
> > Any good reason why in binary_to_float with a scientific notation the
> coefficient must be a float?
>
> binary_to_float/1 follows the format of floats in Erlang. 2e-1 is illegal
> syntax in Erlang so binary_to_float/1 crashes on it.
>
> Regards.
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20150130/16972dd7/attachment.htm>


More information about the erlang-questions mailing list