[erlang-questions] Bug in erlang?

Richard Carlsson carlsson.richard@REDACTED
Sat Jul 13 14:33:14 CEST 2013

On 2013-07-13 06:33 , Mike Oxford wrote:
>  From the command-line, everything is expected and looks correct...
> list_to_float(lists:flatten(io_lib:format("~.2f",[1.000000e+00]))).
> 1.00
> But inside of a .beam'd module...
>                                              erlang:display(V),
> erlang:display(lists:flatten(io_lib:format("~.2f",[V]))),
>                                              V2 =
> list_to_float(lists:flatten(io_lib:format("~.2f",[V]))),
>                                              erlang:display(V2)
> gives...
> 1.000000e+00
> "1.00"
> 1.000000e+00
> So the interesting part is that it (list_to_float) works as expected
> in the shell, but not in a compiled .beam file.

It's not a problem with list_to_float - I'm sure it gives you the same 
value in both cases. But in the first case you let the shell use its 
default formatting of values to print the float, and in the second case 
you use erlang:display(), which is a debugging function that always 
prints floats in a fixed format. Try using erlang:display() on the 
result on the command line and see, or use io:format(...) instead of 
erlang:display() to show the result in the module.

To convince yourself further, you could use term_to_binary(V) on the 
floats in both cases and print the binary representation (e.g. use 
binary_to_list() and print the byte values).


More information about the erlang-questions mailing list