title: How do I set precision while using type double / float in C++
body: <p>In my previous question <a href="https://stackoverflow.com/questions/10419377/comparing-a-double-and-int-without-casting-or-conversion">Comparing a double and int, without casting or conversion</a>, I found out how the the difference between two doubles was tripping the comparison. </p>
  
  <p>I came accross the method setprecision(), which will help display all the numbers after decimal. </p>
  
  <p>So, the difference of 6.15 and 3.15 was found to be : 3.00000000000000044408920985006</p>
  
  <p>Now, when it gets compared with 3, it returns a result saying it is greater than 3. </p>
  
  <p>How do I force it to take only a limited number of digits?</p>
  
  <p>When I used 6.1 and 3.1, the difference was : 2.99999999999999955591079014994</p>
  
  <p>How should I make the precision so that we know that it is actually equal to 3, and not less than.</p>