title: What logic works behind the rounding off of floating point number in c language?
body: <p>I have written a program in c language to roundoff floating point number but the output of the program does not follow any logic.
  The code is--&gt;</p>
  <pre><code>#include&lt;stdio.h&gt;
  
  int main(){
      float a=2.435000;
      float b=2.535000;
      float c=2.635000;
      float d=2.735000;
      float e=2.835000;
      //Rounding off the floating point numbers to 2 decimal places
      printf(&quot;%f  %.2f\n&quot;,a,a);
      printf(&quot;%f  %.2f\n&quot;,b,b);
      printf(&quot;%f  %.2f\n&quot;,c,c);
      printf(&quot;%f  %.2f\n&quot;,d,d);
      printf(&quot;%f  %.2f\n&quot;,e,e);
  
  
      return 0;
  }
  </code></pre>
  <p><strong>OUTPUT:</strong></p>
  <p>2.435000  2.43</p>
  <p>2.535000  2.54</p>
  <p>2.635000  2.63</p>
  <p>2.735000  2.73</p>
  <p>2.835000  2.84</p>
  <p>All the floating numbers have same pattern of digits i.e. they are in the form of 2.x35000 where x is different in different numbers.
  I am not getting why they are showing different behaviour while getting roundoff ,either they should give 2.x3 or 2.x4 but for different x it is giving different value.</p>
  <p>What is the logic behind this?</p>