<div dir="ltr">Erlang R16B01 (erts-5.10.2) [async-threads:10]<br><br>Eshell V5.10.2  (abort with ^G)<br>1> V = 1.000000e+00.<br>1.0<br>2> erlang:display(V).<br>1.000000e+00<br>true<br>3> erlang:display(lists:flatten(io_lib:format("~.2f",[V]))).<br>
"1.00"<br>true<br>4> V2 = list_to_float(lists:flatten(io_lib:format("~.2f",[V]))).<br>1.0<br>5> erlang:display(V2).<br>1.000000e+00<br>true<br>6> <br></div><div class="gmail_extra"><br><br><div class="gmail_quote">
2013/7/13 Richard Carlsson <span dir="ltr"><<a href="mailto:carlsson.richard@gmail.com" target="_blank">carlsson.richard@gmail.com</a>></span><br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div class="im">On 2013-07-13 06:33 , Mike Oxford wrote:<br>
</div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="im">
 From the command-line, everything is expected and looks correct...<br>
<br></div><div class="im">
list_to_float(lists:flatten(<u></u>io_lib:format("~.2f",[1.<u></u>000000e+00]))).<br>
1.00<br>
<br>
But inside of a .beam'd module...<br>
                                             erlang:display(V),<br>
<br>
erlang:display(lists:flatten(<u></u>io_lib:format("~.2f",[V]))),<br>
                                             V2 =<br>
list_to_float(lists:flatten(<u></u>io_lib:format("~.2f",[V]))),<br>
                                             erlang:display(V2)<br>
<br>
gives...<br>
<br>
1.000000e+00<br>
"1.00"<br>
1.000000e+00<br>
<br>
So the interesting part is that it (list_to_float) works as expected<br>
in the shell, but not in a compiled .beam file.<br>
</div></blockquote>
<br>
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.<br>

<br>
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).<span class="HOEnZb"><font color="#888888"><br>

<br>
   /Richard</font></span><div class="HOEnZb"><div class="h5"><br>
<br>
______________________________<u></u>_________________<br>
erlang-questions mailing list<br>
<a href="mailto:erlang-questions@erlang.org" target="_blank">erlang-questions@erlang.org</a><br>
<a href="http://erlang.org/mailman/listinfo/erlang-questions" target="_blank">http://erlang.org/mailman/<u></u>listinfo/erlang-questions</a><br>
</div></div></blockquote></div><br></div>