<div dir="auto">~p is a lossless format for floats that uses a conservative number of digits (since R12B02). See <span style="font-family:"Segoe UI","Segoe WP",Arial,sans-serif;font-size:17px;color:rgb(25,37,39)">OTP-7084. The implementation was based on mochinum:digits/1 from mochiweb.</span></div><div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Fri, May 7, 2021 at 03:26 Richard O'Keefe <<a href="mailto:raoknz@gmail.com">raoknz@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;padding-left:1ex;border-left-color:rgb(204,204,204)"><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">themba.jonga@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;padding-left:1ex;border-left-color:rgb(204,204,204)"><div dir="ltr">Hi, again.<div><br></div><div>Following a response I got from <span style="font-size:0.875rem;letter-spacing:0.2px;white-space:nowrap;color:rgb(32,33,36)"><font face="Roboto, RobotoDraft, Helvetica, Arial, sans-serif" style="font-family:Roboto,RobotoDraft,Helvetica,Arial,sans-serif;color:rgb(32,33,36)">Dmitry Klionsky, perhaps it makes sense for </font><b><font face="tahoma, sans-serif" style="font-family:tahoma,sans-serif;color:rgb(32,33,36)">float_to_list(N)</font></b><font face="Roboto, RobotoDraft, Helvetica, Arial, sans-serif" style="font-family:Roboto,RobotoDraft,Helvetica,Arial,sans-serif;color:rgb(32,33,36)"> to be made into a wrapper for</font></span><span style="font-size:0.875rem;font-weight:bold;letter-spacing:0.2px;font-family:Roboto,RobotoDraft,Helvetica,Arial,sans-serif;white-space:nowrap;color:rgb(32,33,36)"> </span><b><font face="tahoma, sans-serif" style="font-family:tahoma,sans-serif;color:rgb(0,0,0)">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" style="color:rgb(0,0,0)"></font> </div></div></div></div></div><br></div><div id="m_4119889666038623623gmail-m_-2114829433146319840m_1222824999368714802DAB4FAD8-2DD7-40BB-A1B8-4E2AA1F9FDF2"><br>
<table style="border-top-width:1px;border-top-style:solid;border-top-color: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"><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;font-size:13px;font-family:Arial,Helvetica,sans-serif;line-height:18px;color:rgb(65,66,78)">Virus-free. <a href="http://www.avg.com/email-signature?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail" style="font-family:Arial,Helvetica,sans-serif;color:rgb(68,83,234)" target="_blank">www.avg.com</a>
                </td>
        </tr>
</tbody></table><a href="#m_4119889666038623623_m_-2114829433146319840_m_1222824999368714802_DAB4FAD8-2DD7-40BB-A1B8-4E2AA1F9FDF2" width="1" height="1"></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">scott_ribe@elevated-dev.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;padding-left:1ex;border-left-color:rgb(204,204,204)">> On May 5, 2021, at 10:20 AM, <a href="mailto:2QdxY4RzWzUUiLuE@potatochowder.com" target="_blank">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_4119889666038623623gmail-m_-2114829433146319840DAB4FAD8-2DD7-40BB-A1B8-4E2AA1F9FDF2"><br>
<table style="border-top-width:1px;border-top-style:solid;border-top-color: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"><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;font-size:13px;font-family:Arial,Helvetica,sans-serif;line-height:18px;color:rgb(65,66,78)">Virus-free. <a href="http://www.avg.com/email-signature?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail" style="font-family:Arial,Helvetica,sans-serif;color:rgb(68,83,234)" target="_blank">www.avg.com</a>
                </td>
        </tr>
</tbody></table><a href="#m_4119889666038623623_m_-2114829433146319840_DAB4FAD8-2DD7-40BB-A1B8-4E2AA1F9FDF2" width="1" height="1"></a></div>
</blockquote></div>
</blockquote></div></div>