C# Printing Significant Digits
<p>I'm attempting to create graph axis labels; the physical text.  I know how to get the label and print the label using GDI, but my algorithm doesn't do a great job of printing with fractional steps.</p>

<p>To print my labels, I currently, get the first label and then add a step to each label:</p>

<p>public static void PrintLabels(double start, double end, double step);
{
    double current = start;</p>

<pre><code>while (current &lt;= end)
{
     gfx.DrawString(current.ToString(),...); 
     current += step;
}
</code></pre>

<p>}</p>

<p>Is there a number.ToString("something") that will printout decimals if they are there, otherwise, just the whole part?  I would first check if either start, end or step contains a fractional part, then if yes, print all labels with a decimal.</p>
