<p>It's been quite a while since I last used <a href="http://digitalmars.com/d" rel="nofollow noreferrer">D Programming Language</a>, and now I'm using it for some project that involves scientific calculations.</p>

<p>I have a bunch of floating point data, but when I print them using <code>writefln</code>, I get results like: <code>4.62593E-172</code> which is a zero! How do I use string formatting % stuff to print such things as 0?</p>

<p>Right now I'm using a hack:   </p>

<pre><code>    if( abs(a) &lt; 0.0000001 )
        writefln(0);
    else
        writefln(a);
</code></pre>

<p>it does the job, but I want to do it using the formatting operations, if possible.</p>

<p><strong>UPDATE</strong></p>

<p>someone suggested <code>writefln("%.3f", a)</code> but the problem with it is that it prints needless extra zeros, i.e. <code>0</code> becomes <code>0.000</code> and <code>1.2</code> becomes <code>1.200</code><br>
Can I make it also remove the trailing zeros?</p>

Try something like
```
```
writefln("%.3f", a);
```
```