<div dir="ltr">Paul & I experimented a bit with numeric output, to see what the effect of the precision parameter really is currently.  It definitely seems a bit... odd.<div><br></div><div>Consider this:</div><div><br></div><div><pre class="gmail-c-mrkdwn__pre" style="box-sizing:inherit;margin-top:4px;margin-bottom:4px;padding:8px;font-size:12px;line-height:1.50001;font-variant-ligatures:none;white-space:pre-wrap;word-break:normal;border-radius:4px;color:rgb(29,28,29);font-family:Monaco,Menlo,Consolas,"Courier New",monospace">select i, ST_AsText('POINT(12345678.123456789 1)'::geometry, i ) </pre><pre class="gmail-c-mrkdwn__pre" style="box-sizing:inherit;margin-top:4px;margin-bottom:4px;padding:8px;font-size:12px;line-height:1.50001;font-variant-ligatures:none;white-space:pre-wrap;word-break:normal;border-radius:4px;color:rgb(29,28,29);font-family:Monaco,Menlo,Consolas,"Courier New",monospace">from generate_series(0,20) as t(i);</pre><pre class="gmail-c-mrkdwn__pre" style="box-sizing:inherit;margin-top:4px;margin-bottom:4px;padding:8px;font-size:12px;line-height:1.50001;font-variant-ligatures:none;white-space:pre-wrap;word-break:normal;border-radius:4px;color:rgb(29,28,29);font-family:Monaco,Menlo,Consolas,"Courier New",monospace"> i  |           st_astext            <br style="box-sizing:inherit">----+--------------------------------<br style="box-sizing:inherit">  0 | POINT(12345678 1)<br style="box-sizing:inherit">  1 | POINT(12345678.1 1)<br style="box-sizing:inherit">  2 | POINT(12345678.12 1)<br style="box-sizing:inherit">  3 | POINT(12345678.123 1)<br style="box-sizing:inherit">  4 | POINT(<a target="_blank" class="gmail-c-link" href="tel:123456781235" rel="noopener noreferrer" style="box-sizing:inherit;color:inherit;text-decoration-line:none">12345678.1235</a> 1)<br style="box-sizing:inherit">  5 | POINT(12345678.12346 1)<br style="box-sizing:inherit">  6 | POINT(12345678.123457 1)<br style="box-sizing:inherit">  7 | POINT(12345678.1234568 1)<br style="box-sizing:inherit">  8 | POINT(12345678 1)<br style="box-sizing:inherit">  9 | POINT(12345678.1 1)<br style="box-sizing:inherit"> 10 | POINT(12345678.12 1)<br style="box-sizing:inherit"> 11 | POINT(12345678.123 1)<br style="box-sizing:inherit"> 12 | POINT(<a target="_blank" class="gmail-c-link" href="tel:123456781235" rel="noopener noreferrer" style="box-sizing:inherit;color:inherit;text-decoration-line:none">12345678.1235</a> 1)<br style="box-sizing:inherit"> 13 | POINT(12345678.12346 1)<br style="box-sizing:inherit"> 14 | POINT(12345678.123457 1)<br style="box-sizing:inherit"> 15 | POINT(12345678.1234568 1)<br style="box-sizing:inherit"> 16 | POINT(12345678.12345679 1)<br style="box-sizing:inherit"> 17 | POINT(12345678.123456789 1)<br style="box-sizing:inherit"> 18 | POINT(12345678.1234567892 1)<br style="box-sizing:inherit"> 19 | POINT(12345678.12345678918 1)<br style="box-sizing:inherit"> 20 | POINT(12345678.123456789181 1)</pre>But then this:</div><div><pre class="gmail-c-mrkdwn__pre" style="box-sizing:inherit;margin-top:4px;margin-bottom:4px;padding:8px;font-size:12px;line-height:1.50001;font-variant-ligatures:none;white-space:pre-wrap;word-break:normal;border-radius:4px;color:rgb(29,28,29);font-family:Monaco,Menlo,Consolas,"Courier New",monospace">select i, ST_AsText('POINT(123.123456789 1)'::geometry, i )                                                    from generate_series(0,20) as t(i);<br style="box-sizing:inherit"> i  |           st_astext            <br style="box-sizing:inherit">----+--------------------------------<br style="box-sizing:inherit">  0 | POINT(123 1)<br style="box-sizing:inherit">  1 | POINT(123.1 1)<br style="box-sizing:inherit">  2 | POINT(123.12 1)<br style="box-sizing:inherit">  3 | POINT(123.123 1)<br style="box-sizing:inherit">  4 | POINT(123.1235 1)<br style="box-sizing:inherit">  5 | POINT(123.12346 1)<br style="box-sizing:inherit">  6 | POINT(123.123457 1)<br style="box-sizing:inherit">  7 | POINT(123.1234568 1)<br style="box-sizing:inherit">  8 | POINT(123.12345679 1)<br style="box-sizing:inherit">  9 | POINT(123.123456789 1)<br style="box-sizing:inherit"> 10 | POINT(123.123456789 1)<br style="box-sizing:inherit"> 11 | POINT(123.123456789 1)<br style="box-sizing:inherit"> 12 | POINT(123.123456789 1)<br style="box-sizing:inherit"> 13 | POINT(123.123456789 1)<br style="box-sizing:inherit"> 14 | POINT(123.123456789 1)<br style="box-sizing:inherit"> 15 | POINT(123.123456789 1)<br style="box-sizing:inherit"> 16 | POINT(123.123456789 1)<br style="box-sizing:inherit"> 17 | POINT(123.123456789 1)<br style="box-sizing:inherit"> 18 | POINT(123.123456789000002 1)<br style="box-sizing:inherit"> 19 | POINT(123.1234567890000022 1)<br style="box-sizing:inherit"> 20 | POINT(123.12345678900000223 1)</pre>The second test is working as expected.  The first one, not so much.  It looks like at 15 TOTAL digits, a switch happens to change to limiting the TOTAL digits, rather than the decimal places.  Not sure why that doesn't happen in the second case.</div><div><br></div><div>So this might explain why specifying a large precision doesn't actually provide that level of precision (at least for larger-magnitude numbers).  </div><div><br></div><div>It would be nice to fix this.</div><div><br></div><div>A proposal that fixes this problem, has relatively simple semantics, and doesn't require changing the precision default value is:</div><div><br></div><div>- for precision < 15, decimal places are limited to that precision</div>- for precision >= 15, full precision is output (supporting round-tripping)<div><br></div><div>Notes:</div><div>- for very large magnitude numbers PostGIS switches to scientific notation for output.  This may not be ideal, but it does mean that the size of output text is bounded (to around 30 chars max).</div><div>- for any precision, trailing zeros are dropped.  So a number could still output with only a few chars, if it doesn't have many sig digits (e.g. 1.5)</div><div><br></div><div>Questions:</div><div>- does this solve the problem of round-tripping?</div><div>- How much impact does it have on unit tests?</div><div>- How can this be implemented? (hopefully there are some numeric output routines in place which can provide this)</div><div><br></div><div><div><br></div></div></div>