How %g works in printf
<p>The <code>%g</code> description says</p>

<blockquote>
  <p>Use the shortest representation: <code>%e</code> or <code>%f</code></p>
</blockquote>

<p>for example,
<code>544666.678</code> is written as <code>544667</code> if <code>%.6g</code> is used which is fine.</p>

<p>But the same number is written as <code>5.4467E+5</code> when <code>%.5g</code> is used.</p>

<p>Why would it use exponential notation (<code>%e</code>) here while <code>544670</code> (<code>%f</code>) is shorter in length than that.</p>

<p>Can anyone please help me to understand? Is this a bug?</p>

<p>Similarly, <code>44.35</code> is written as <code>44.4</code> when <code>%.1f</code> is used which is fine.
but <code>44.55</code> is written as <code>44.5</code> when <code>%.1f</code> is used. Why isn't it written as <code>44.6</code>? Is this a bug?</p>