[erlang-questions] convert strings like "1e-8" to floats.

Oleksii Semilietov spylik@REDACTED
Tue Feb 7 10:54:59 CET 2017

Hi all!

I playing with converting binaries and lists to floats and I found
something what I can't solve via elegant way. I believe it's my leakage of
understanding floats.

So, what is different between 1e-8 and 1.0e-8 ?

For example we have float as list "0.01".  It is easy to convert it to
float just via list_to_float("0.01").
But when floats coming from external world as binaries or lists which looks
like "1e-8", and not like "1.0e-8", I can't find proper way to convert it.

For example in PHP both 1e-8 and 1.0e-8 is equivalent
var_dump(floatval("1e-8") === floatval("1.0e-8")) returns true.
Javascript 1E-8 === 1.0E-8 is also true.

In Erlang

list_to_float("1.0E-8") =:= 0.00000001


list_to_float("1E-8") =:= 0.00000001.
** exception error: bad argument in function list_to_float/1 called as

How to convert it via right way?

Oleksii D. Semilietov
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20170207/a8f873b5/attachment.htm>

More information about the erlang-questions mailing list