 <p>You can use <code>sprintf</code> and then trim the zeros. This is the same idea as @Havenard's answer, but writing spaces over the zeros instead of cutting the string. And my C-style is somewhat different FWIW. My style is that I don't want to count or do any arithmetic in my head; that's what the C optimizer is for :).</p> <pre><code>#include &lt;math.h&gt; #include &lt;stdio.h&gt; #include &lt;string.h&gt; int main() { int kPower; for(kPower=-4; kPower&lt;5; kPower++){ enum { bufsize = 2+5+10+1+4+1+1 }; char buf[bufsize]; int j,n,i; double raisePower = pow(10,kPower); //printf("%2d %10.4f\n",kPower,raisePower); snprintf(buf,bufsize,"%2d %10.4f\n",kPower,raisePower); j=strchr(buf,'.')-buf; j+=1; n=strchr(buf+j,'\n')-buf; for (i=n-1; i&gt;j; i--) if (buf[i]=='0') buf[i]=' '; else break; printf("%s",buf); } return 0; } </code></pre> <p>Output:</p> <pre><code>-4 0.0001 -3 0.001 -2 0.01 -1 0.1 0 1.0 1 10.0 2 100.0 3 1000.0 4 10000.0 </code></pre>