Write floating point numbers without any decimal places
<p>I'm trying to have Python replicate some FORTRAN output of real values. My FORTRAN prints the real value as "31380.". I'm trying to replicate the same in Python--note that although I have no decimal places, I actually want the decimal point (period) to be printed. My current code is</p>

<pre><code>htgm=31380.
print '{:6.0f}'.format(htgm)
</code></pre>

<p>which yields "31380". What am I doing wrong?</p>

<p>Python format language includes an 'alternate' form for floats which forces the decimal point by using a '#' in the format string:</p>

<pre><code>&gt;&gt;&gt; htgm=31380.
&gt;&gt;&gt; format(htgm, '#.0f')
'31380.'
</code></pre>

<p>Which is what I think you are looking for.<br>
I thought <code>#g</code> would be what you wanted but for some reason python adds the <code>0</code> back on:</p>

<pre><code>&gt;&gt;&gt; htgm=31380.
&gt;&gt;&gt; format(htgm, 'g')
'31380'
&gt;&gt;&gt; format(htgm, '#g')
'31380.0'
</code></pre>

python string format