<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class="">I think for the sake of the OP "round trip" needs explaining:<div class=""><br class=""></div><div class="">It does not mean that “arbitrary float string X” -> float -> “string identical to X” is true.</div><div class=""><br class=""></div><div class="">It does however mean: float Y -> string representation -> float Y.</div><div class=""><br class=""></div><div class="">One problem is that many fractions like e.g. the simple example of decimal 0.1 are representable as a finite binary fraction:</div><div class=""><br class=""></div><div class="">0.1 base 10 is 0.00011001100110011… base 2 (where … means its a infinite repetition of the digits 0011)</div><div class=""><br class=""></div><div class="">So converting seemingly harmless base 10 floating point strings result in infinite binary fractions. Then it depends on how they are rounded if conversion back to base 10 string gives you the same string or a rounding error shows.</div><div class=""><br class=""></div><div class="">Cheers,</div><div class="">-- Peer <br class=""><div><br class=""><blockquote type="cite" class=""><div class="">On 7. May 2021, at 13:57, Thomas Depierre <<a href="mailto:depierre.thomas@gmail.com" class="">depierre.thomas@gmail.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="auto" class=""><div class="">That is not true.<div dir="auto" class=""><br class=""></div><div dir="auto" class="">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" class=""><br class=""></div><div dir="auto" class="">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" class=""><br class=""></div><div dir="auto" class="">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" class=""><br class=""></div><div dir="auto" class="">Kindly,</div><div dir="auto" class=""><br class=""></div><div dir="auto" class="">Thomas Depierre</div><br class=""><br class=""><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" class="">raoknz@gmail.com</a>> wrote:<br class=""></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr" class=""><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 class=""></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 class=""></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 class=""></div></div><br class=""><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" class="">themba.jonga@gmail.com</a>> wrote:<br class=""></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" class="">Hi, again.<div class=""><br class=""></div><div class="">Following a response I got from <span style="color:rgb(32,33,36);font-size:0.875rem;letter-spacing:0.2px;white-space:nowrap" class=""><font face="Roboto, RobotoDraft, Helvetica, Arial, sans-serif" class="">Dmitry Klionsky, perhaps it makes sense for </font><b class=""><font face="tahoma, sans-serif" class="">float_to_list(N)</font></b><font face="Roboto, RobotoDraft, Helvetica, Arial, sans-serif" class=""> 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" class=""> </span><b class=""><font face="tahoma, sans-serif" class="">lists:flatten(io_lib:format("~p",[N]))?</font></b><br class=""><div class=""><div dir="ltr" class=""><div dir="ltr" class=""><div class=""><div class=""><br class=""></div><div class="">Eshell V11.1 (abort with ^G)<br class="">1> N = 4.4445.<br class="">4.4445<br class="">2> lists:flatten(io_lib:format("~p",[N])).<br class="">"4.4445"<br class="">3> P = 5.4443.<br class="">5.4443<br class="">4> lists:flatten(io_lib:format("~p",[P])).<br class="">"5.4443"<br class="">5> Q = 1.2345678.<br class="">1.2345678<br class="">6> lists:flatten(io_lib:format("~p",[Q])).<br class="">"1.2345678"<br class="">7> float_to_list(Q).<br class="">"1.23456779999999999298e+00"<br class="">8> <br class=""></div><div class=""><br class=""></div><div class="">Regards</div><div class=""> </div><div class=""><strong class="">Themba Jonga</strong></div><div class=""><font size="1" class=""></font> </div></div></div></div></div><br class=""></div><div id="m_6571645775151075267gmail-m_-2114829433146319840m_1222824999368714802DAB4FAD8-2DD7-40BB-A1B8-4E2AA1F9FDF2" class=""><br class="">
<table style="border-top:1px solid rgb(211,212,222)" class="">
<tbody class=""><tr class="">
<td style="width:55px;padding-top:13px" class=""><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" class=""><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" class=""></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" class="">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" class="">www.avg.com</a>
</td>
</tr>
</tbody></table><a href="x-msg://10/#m_6571645775151075267_m_-2114829433146319840_m_1222824999368714802_DAB4FAD8-2DD7-40BB-A1B8-4E2AA1F9FDF2" width="1" height="1" rel="noreferrer" class=""></a></div></div><br class=""><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" class="">scott_ribe@elevated-dev.com</a>> wrote:<br class=""></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" class="">2QdxY4RzWzUUiLuE@potatochowder.com</a> wrote:<br class="">
> <br class="">
> In short, no.<br class="">
<br class="">
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 class="">
<br class="">
<br class="">
</blockquote></div>
<div id="m_6571645775151075267gmail-m_-2114829433146319840DAB4FAD8-2DD7-40BB-A1B8-4E2AA1F9FDF2" class=""><br class="">
<table style="border-top:1px solid rgb(211,212,222)" class="">
<tbody class=""><tr class="">
<td style="width:55px;padding-top:13px" class=""><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" class=""><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" class=""></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" class="">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" class="">www.avg.com</a>
</td>
</tr>
</tbody></table><a href="x-msg://10/#m_6571645775151075267_m_-2114829433146319840_DAB4FAD8-2DD7-40BB-A1B8-4E2AA1F9FDF2" width="1" height="1" rel="noreferrer" class=""></a></div>
</blockquote></div>
</blockquote></div></div></div>
</div></blockquote></div><br class=""></div></body></html>