title: Print a floating point number as a decimal number with printf()
body: <p><em>I found a very good answer to this question on <a href="https://stackoverflow.com/questions/7480097/what-happens-to-a-float-variable-when-d-is-used-in-a-printf">this thread</a></em></p>
  
  <p>I want to understand a little bit more about why <strong>printf()</strong> can't print a floating point number as a decimal (with %d).</p>
  
  <p>The program is a simple one converting Fahrenheit to Celsius degree.</p>
  
  <p>I understand that <strong>%.f</strong> or <strong>%.0f</strong> is doing what i want.
  But when i try to do the same thing with <strong>%d</strong>, <em>the output is unpredictable</em>.</p>
  
  <p>I searched for more detailed pieces of information <a href="http://www.cplusplus.com/reference/cstdio/printf/" rel="nofollow noreferrer">cplusplus</a>, but i don't see where it overflows or why i get this result. For example, if you use an uninitialized variable, you will get some random (or not so random) value that is in that place of memory where your variable's name is "pointing" towards. Here, what is the reason ?</p>
  
  <pre><code>float fahr, celsius;
  int lower, upper, step;
  
  lower = 0;    upper = 300;    step = 20;
  
  fahr = lower;
  while(fahr &lt;= upper){
      celsius = (5 / 9.) * (fahr - 32);
  
      printf("%d\t%d\n",fahr,celsius);
  
      fahr+=step;
  }
  </code></pre>
  
  <p>i was expecting :
  0 20 40 60  .... 300 (first column)
  -17, -6, -4, ...    (second column)</p>
  
  <p>instead i got
  0 0 0 0 0 0 0 ,,, 0 (first column)
  0, 1077149696, 1078198272, ... (second column)</p>