title: float to string using roundtrip
body: <p>I'm trying to convert a float to it's string representation without the result appearing in scientific notation.</p>
  
  <p>I first tried :</p>
  
  <pre><code>ToString("0." + new string('#', 7))
  </code></pre>
  
  <p>but this doesn't seem to work for large values. For example :</p>
  
  <pre><code>float largeNumber = 12345678f;
  string str = largeNumber.ToString("0." + new string('#', 7));
  </code></pre>
  
  <p>results in <code>"12345680"</code></p>
  
  <p>I then tried <code>ToString("R")</code></p>
  
  <p>this works for the large number above, but if the numbers get too large, it displays them in scientific notation. For example <code>5000000000f</code> results in <code>"5E+09"</code>. And small numbers like <code>0.0005</code> result in <code>0.0004999999966</code></p>
  
  <p>I've also tried mixing the 2, but I still get scientific notation in some cases.</p>
  
  <p>My test program is pasted below. I appreciate that there will be precision issues, but I'm wondering if I can do any better than what I have?</p>
  
  <pre><code>class Program
  {
      static void Main(string[] args)
      {
          Write(0.123456789f);
          Write(0.12345678f);
          Write(0.1234567f);
          Write(0.123456f);
          Write(0.12345f);
          Write(0.1234f);
          Write(0.123f);
          Write(0.12f);
          Write(0.1f);
          Write(1);
          Write(12);
          Write(123);
          Write(1234);
          Write(12345);
          Write(123456);
          Write(1234567);
          Write(12345678);
          Write(123456789);
  
          Console.WriteLine();
  
          float f = 5000000000f;
          for (int i = 0; i &lt; 17; ++i)
          {
              Write(f);
              f /= 10;
          }
  
          Console.WriteLine();
  
          f = 5000000000f;
          for (int i = 0; i &lt; 17; ++i)
          {
              Write(f &lt; 1 ? f + 1 : f);
              f /= 10;
          }
  
          Console.Read();
      }
  
      static void Write(float f)
      {
          //string str = f.ToString("0." + new string('#', 7));
          //string str = f.ToString("R");
          string str = Math.Abs(f) &lt; 1 ? f.ToString("0." + new string('#', 7)) : f.ToString("R");
  
          Console.WriteLine(str);
      }
  }
  </code></pre>