title: How to round a number in C?
body: <p>I tried searching this up on Stack Overflow but couldn't find an answer.</p>
  <p>Here is the code:</p>
  <pre><code>#include &lt;stdio.h&gt;
  
  int main(void) {
   
  
  double y;
  printf(&quot;Enter a number: &quot;);
  scanf(&quot;%lf&quot;, &amp;y);
  printf(&quot;Your number when rounded is: %.2lf&quot;, y); 
  //If user inputs 5.05286, how can i round off this number so as to get the output as 5.00
  //I want the output to be rounded as well as to be 2 decimal places like 10.6789 becomes 11.00
  
  
  return 0;
  }
  </code></pre>
  <p>I want to round a number, for example, if the number is <code>5.05286</code>, it should be rounded to <code>5.00</code>, and if it is <code>5.678901</code>, it will be rounded to <code>6.00</code> with <code>2</code>decimal places. The number <code>5.678901</code> is getting rounded to <code>5.05</code> but it should round to <code>5</code>. I am aware that I can use <code>floor()</code> and <code>ceil()</code>, but I don't think I will be able to round off the answer without conditional statements, which is not the scope of my <code>C</code> knowledge. I also tried to use the <code>round()</code> function but it doesn't round at all.</p>