title: Json.NET serializing float/double with minimal decimal places, i.e. no redundant ".0"?
body: <p>When serializing floats and doubles, Json.NET always adds ".0" at the end if the number doesn't contain any fractional part. I was wondering if there was an easy way to bypass this, to result in a more compact representation? The extra periods and zeroes add up when serializing an object containing many numbers.</p>
  
  <p>For example, when running this code:</p>
  
  <pre><code>JsonConvert.SerializeObject(1.0);
  </code></pre>
  
  <p>I would expect (and want) this result:</p>
  
  <pre><code>"1"
  </code></pre>
  
  <p>But instead I get:</p>
  
  <pre><code>"1.0"
  </code></pre>
  
  <p>I looked at the source code and noticed that it was purposely added in commit <a href="https://github.com/JamesNK/Newtonsoft.Json/commit/0319263756212f4a1875cda6534b9b8e1fb53188">0319263</a> (<em>"...-Fixed JsonConvert to always write a floating point number with a decimal place..."</em>) where it runs code that looks basically like:</p>
  
  <pre><code>    private static string EnsureDecimalPlace(double value, string text)
      {
          if (double.IsNaN(value) || double.IsInfinity(value) ||
              text.IndexOf('.') != -1 || text.IndexOf('E') != -1 ||
              text.IndexOf('e') != -1)
          {
              return text;
          }
  
          return text + ".0";
      }
  </code></pre>
  
  <p>Consequently, I am wondering:</p>
  
  <ol>
  <li><p>What may have been the reason for that change? The <a href="http://www.json.org/">JSON specification</a> does not seem to require it.</p></li>
  <li><p>Is there an easy way to bypass it?</p></li>
  </ol>