title: printf in different forms
body: <p>I have a data type of <code>double</code>, I want to <code>printf</code> the double in the following form:</p>
  
  <ul>
  <li>If <code>double x=2</code> or <code>x=2.0</code> print <code>2</code> to the screen, which means if I get an integer I print an integer.</li>
  <li>If <code>double x=2.3</code> or <code>x=2.30</code> or any other non-whole number I print <code>2.3</code> to the screen.</li>
  </ul>
  
  <p>Is there any way to do it shortly? or do I need to use if statements or something like that?</p>
  
  <pre><code>double x = 2;
  printf("%d", x);
  double x = 2.3;
  printf("%.1f", x);
  </code></pre>
  
  <p>This is an illustration only.
  I want to <code>printf</code> an integer or a double based on the value I get.</p>