float_to_list vs io:format ~w

Viktor Söderqvist viktor@REDACTED
Mon Jun 28 11:23:04 CEST 2021


Hi!

Apparently, float_to_binary/1 and float_to_list/1 return a different 
textual representation than io:format("~w", [Float]) and the shell.

     Eshell V11.1.8  (abort with ^G)
     1> float_to_list(10.2).
     "1.01999999999999992895e+01"
     2> 1.01999999999999992895e+01.
     10.2
     3> io:format("~w~n", [10.2]).
     10.2
     ok
     4> 1.01999999999999992895e+01 =:= 10.2.
     true

Apparently, both are correct textual representations of the same 
floating point value. Why don't they use the same algorithm?

Viktor


More information about the erlang-questions mailing list