<div dir="auto"><div>That is not true.<div dir="auto"><br></div><div dir="auto">The formatting used in format ~p is the shortest round trip one. This will be different for every single binary floating point number but also be far shorter and readable. There is work in progress to bring this as an option in float_to_list/2 thanks to the recent work in Ryu and Dragonbox.</div><div dir="auto"><br></div><div dir="auto">Having a fixed precision already exist in float_to_list/2. This works as printf %f. I strongly advise to not use it as this precision does not translate well to the binary format precision loss.</div><div dir="auto"><br></div><div dir="auto">I understand that float to string and string to float conversion are thought as niche topic, so i will be happy to provide all the bibliography you may need to explore it if you are surprised by my explanations.</div><div dir="auto"><br></div><div dir="auto">Kindly,</div><div dir="auto"><br></div><div dir="auto">Thomas Depierre</div><br><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Fri, 7 May 2021, 12:27 Richard O'Keefe, <<a href="mailto:raoknz@gmail.com">raoknz@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div class="gmail_default" style="font-family:monospace,monospace">No, making float_to_list/1 a wrapper for format... does not make sense.</div><div class="gmail_default" style="font-family:monospace,monospace">float_to_list/1 is meant to give you an accurate representation of the</div><div class="gmail_default" style="font-family:monospace,monospace">value.  Two different floats, no matter how small the difference,</div><div class="gmail_default" style="font-family:monospace,monospace">should result in different lists.  It's meant for converting a float</div><div class="gmail_default" style="font-family:monospace,monospace">to text that you can send to another machine and reconstitute the</div><div class="gmail_default" style="font-family:monospace,monospace">same value there.  This will usually result in more digits than a human</div><div class="gmail_default" style="font-family:monospace,monospace">would normally want to see.</div><div class="gmail_default" style="font-family:monospace,monospace"><br></div><div class="gmail_default" style="font-family:monospace,monospace">If you *want* format ~p, use it!</div><div class="gmail_default" style="font-family:monospace,monospace"><br></div><div class="gmail_default" style="font-family:monospace,monospace">Now perhaps there might be an argument to be made for</div><div class="gmail_default" style="font-family:monospace,monospace">float_to_list(X: number(), N: integer()) -> string()</div><div class="gmail_default" style="font-family:monospace,monospace">returning a string that represents X as accurately as</div><div class="gmail_default" style="font-family:monospace,monospace">possible using N digits.  But that is another discussion.<br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Thu, 6 May 2021 at 20:56, Themba Jonga <<a href="mailto:themba.jonga@gmail.com" target="_blank" rel="noreferrer">themba.jonga@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr">Hi, again.<div><br></div><div>Following a response I got from <span style="color:rgb(32,33,36);font-size:0.875rem;letter-spacing:0.2px;white-space:nowrap"><font face="Roboto, RobotoDraft, Helvetica, Arial, sans-serif">Dmitry Klionsky, perhaps it makes sense for </font><b><font face="tahoma, sans-serif">float_to_list(N)</font></b><font face="Roboto, RobotoDraft, Helvetica, Arial, sans-serif"> to be made into a wrapper for</font></span><span style="color:rgb(32,33,36);font-size:0.875rem;font-weight:bold;letter-spacing:0.2px;font-family:Roboto,RobotoDraft,Helvetica,Arial,sans-serif;white-space:nowrap"> </span><b><font face="tahoma, sans-serif">lists:flatten(io_lib:format("~p",[N]))?</font></b><br><div><div dir="ltr"><div dir="ltr"><div><div><br></div><div>Eshell V11.1  (abort with ^G)<br>1> N = 4.4445.<br>4.4445<br>2> lists:flatten(io_lib:format("~p",[N])).<br>"4.4445"<br>3> P = 5.4443.<br>5.4443<br>4> lists:flatten(io_lib:format("~p",[P])).<br>"5.4443"<br>5> Q = 1.2345678.<br>1.2345678<br>6> lists:flatten(io_lib:format("~p",[Q])).<br>"1.2345678"<br>7> float_to_list(Q).<br>"1.23456779999999999298e+00"<br>8> <br></div><div><br></div><div>Regards</div><div> </div><div><strong>Themba Jonga</strong></div><div><font size="1"></font> </div></div></div></div></div><br></div><div id="m_6571645775151075267gmail-m_-2114829433146319840m_1222824999368714802DAB4FAD8-2DD7-40BB-A1B8-4E2AA1F9FDF2"><br>
<table style="border-top:1px solid rgb(211,212,222)">
        <tbody><tr>
        <td style="width:55px;padding-top:13px"><a href="http://www.avg.com/email-signature?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail" target="_blank" rel="noreferrer"><img src="https://ipmcdn.avast.com/images/icons/icon-envelope-tick-green-avg-v1.png" alt="" style="width:46px;height:29px" width="46" height="29"></a></td>
                <td style="width:470px;padding-top:12px;color:rgb(65,66,78);font-size:13px;font-family:Arial,Helvetica,sans-serif;line-height:18px">Virus-free. <a href="http://www.avg.com/email-signature?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail" style="color:rgb(68,83,234)" target="_blank" rel="noreferrer">www.avg.com</a>
                </td>
        </tr>
</tbody></table><a href="#m_6571645775151075267_m_-2114829433146319840_m_1222824999368714802_DAB4FAD8-2DD7-40BB-A1B8-4E2AA1F9FDF2" width="1" height="1" rel="noreferrer"></a></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Wed, 5 May 2021 at 18:38, Scott Ribe <<a href="mailto:scott_ribe@elevated-dev.com" target="_blank" rel="noreferrer">scott_ribe@elevated-dev.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">> On May 5, 2021, at 10:20 AM, <a href="mailto:2QdxY4RzWzUUiLuE@potatochowder.com" target="_blank" rel="noreferrer">2QdxY4RzWzUUiLuE@potatochowder.com</a> wrote:<br>
> <br>
> In short, no.<br>
<br>
Although many (most, actually nearly all) real numbers cannot be represented precisely as a float, any float can be round-tripped to text and back exactly. This is part of the IEEE floating point standard, actually. (And it's not easy...)<br>
<br>
<br>
</blockquote></div>
<div id="m_6571645775151075267gmail-m_-2114829433146319840DAB4FAD8-2DD7-40BB-A1B8-4E2AA1F9FDF2"><br>
<table style="border-top:1px solid rgb(211,212,222)">
        <tbody><tr>
        <td style="width:55px;padding-top:13px"><a href="http://www.avg.com/email-signature?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail" target="_blank" rel="noreferrer"><img src="https://ipmcdn.avast.com/images/icons/icon-envelope-tick-green-avg-v1.png" alt="" style="width:46px;height:29px" width="46" height="29"></a></td>
                <td style="width:470px;padding-top:12px;color:rgb(65,66,78);font-size:13px;font-family:Arial,Helvetica,sans-serif;line-height:18px">Virus-free. <a href="http://www.avg.com/email-signature?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail" style="color:rgb(68,83,234)" target="_blank" rel="noreferrer">www.avg.com</a>
                </td>
        </tr>
</tbody></table><a href="#m_6571645775151075267_m_-2114829433146319840_DAB4FAD8-2DD7-40BB-A1B8-4E2AA1F9FDF2" width="1" height="1" rel="noreferrer"></a></div>
</blockquote></div>
</blockquote></div></div></div>