[erlang-questions] list_to_float/1 precision

Hoan Ton-That hoan@REDACTED
Sun Dec 17 01:36:55 CET 2006


On 2006-12-17 00:18:06 +1100, Per Hedeland <per@REDACTED> said:

> 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)

Thanks for the explanation.

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






More information about the erlang-questions mailing list