[erlang-questions] list_to_float/1 precision

Per Hedeland <>
Sat Dec 16 14:18:06 CET 2006

Hoan Ton-That <> wrote:
>Is there a way to convert from strings to
>floats that is more precise?
>> list_to_float("-35.244818").

The conversion is as precise as it can be (given 64-bit floats), what
you're seeing is just the default print format of the shell, which AFAIK
is 'p', which for floats is equivalent to 'g', which defaults to 6
significant digits (see the io(3) man page).

1> F=list_to_float("-35.244818").
2> io:format("~p~n",[F]).   
3> io:format("~g~n",[F]).
4> io:format("~.10g~n",[F]).

--Per Hedeland

More information about the erlang-questions mailing list