title: Use scientific notation only if needed
body: <p>I want to parse a <code>double</code> value into a <code>string</code>. I want my number to have a specified number of digits (that I won't know until runtime). If this number can be expressed with a non-zero value in number of digits this is what I want. If the number comes out as zero's like this I want it expressed in scientific notation.</p>
  
  <p>Some examples will make this more clear, this assumes I wanted 3 digits:</p>
  
  <p><strong>Value:</strong> .2367 <strong>Output:</strong> "0.23"</p>
  
  <p><strong>Value:</strong> .00367 <strong>Output:</strong> "3.67E-3"</p>
  
  <p><strong>Value:</strong> 22.3 <strong>Output:</strong> "22.3"</p>
  
  <p><strong>Value:</strong> 3364.0 <strong>Output:</strong> "3.36E3"</p>
  
  <p>My work around solution would use the <a href="http://msdn.microsoft.com/en-us/library/3hfd35ad.aspx" rel="noreferrer">ToString()</a> method and the <code>N</code> <a href="http://msdn.microsoft.com/en-us/library/dwhawy9k.aspx" rel="noreferrer">numeric format string</a> and if it results in zero's revert to the <code>E</code> format string, but this feels like reinventing the wheel. Does anyone know if a built in method to do this?</p>