<span class="gmail_quote"></span>
<div style="DIRECTION: ltr"><br>
<div></div>
<div style="DIRECTION: ltr"><span class="q">
<blockquote class="gmail_quote" style="PADDING-LEFT: 1ex; MARGIN: 0px 0px 0px 0.8ex; BORDER-LEFT: #ccc 1px solid">&gt; &gt;&gt;&gt; print &quot;%14.3g\n%14.3e\n%14.3f&quot; % (bignum,bignum,bignum)<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; 1.23e+009<br>
&gt;&nbsp;&nbsp;&nbsp;&nbsp;1.235e+009<br>&gt; 1234567898.235<br>&gt;<br>&gt; But in practice, we do not know how big is the data in advance when<br>&gt; doing scientific computation in a compiled program.<br><br>That is irrelevant, the format you display the data in has 
<br>no bearing on its precision, the display format is purely to<br>make it more readable.</blockquote>
<div>&nbsp;</div>
<div>&nbsp;</div></span></div>
<div style="DIRECTION: ltr">
<div>Another interesting one:</div>
<div>&nbsp;</div>
<div>&gt;&gt;&gt; a = 123456.78<br>&gt;&gt;&gt; print &quot;%g\n%e\n%f&quot; % (a,a,a)<br>123457<br>1.234568e+005<br>123456.780000<br>&gt;&gt;&gt;</div>
<div>&nbsp;</div>
<div>Float number loses digits and becomes integer in the output ?</div>
<div>&nbsp;</div>
<div>Can we override the %g in python, or adding in some other format identifier so that print statement with custom format string still works ?</div>
<div>&nbsp;</div>
<div>Here if I want to dynamically output floating data based on the number of significant digits (SD) from an input's: </div>
<div>&nbsp;</div>
<div>- If SD &gt; m, truncate (or round it)&nbsp;in the output</div>
<div>- If SD &lt;&nbsp;m, &nbsp;just directly output the number (without padding 0 to the end).</div>
<div>
<div>- In either of above cases, similar to %g, if %e is necessary, just&nbsp;output %e format as result (also truncate the data based on&nbsp;SD in the %e format if necessary).&nbsp;&nbsp;&nbsp;</div>&nbsp;&nbsp;&nbsp; </div>
<div>e.g, if SD = 3:</div>
<div>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; -&nbsp;for input = 100.0, the output is&nbsp;just 100.0 (not 100.00000..), since 100.0 = 1.0 * 10e2 (2&lt;3)</div>
<div>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;- for&nbsp;input =&nbsp;0.01,&nbsp;&nbsp;the output is&nbsp;just 0.01, since 0.01 = 1.0 * 10e-2 (2&lt;3)</div>
<div>&nbsp;&nbsp;&nbsp;&nbsp; - for input with SD &gt; 3,&nbsp;&nbsp;truncate&nbsp;it to output.</div>
<div>&nbsp;</div>
<div>SD can be set to some number (e.g. 6) in the program.</div>
<div>&nbsp;</div>
<div>Thanks.</div>&nbsp;</div></div>