title: cannot round decimals to two decimal places in R
body: <p>I have tried different functions to round decimals to two digits, such as <code>format()</code>, <code>formatC()</code>,<code>signif()</code> and <code>round()</code>. None of them can truly round all decimals to two decimal places.</p>
  
  <p>For example, my data frame DF has three columns: Index, PDF and CDF:</p>
  
  <pre><code>   Index          PDF          CDF
  1  -1.00 8.306360e-07 8.306360e-09
  2  -0.99 8.332774e-07 1.663913e-08
  3  -0.98 8.411712e-07 2.505085e-08
  4  -0.97 8.542267e-07 3.359311e-08
  5  -0.96 8.722951e-07 4.231606e-08
  6  -0.95 8.951719e-07 5.126778e-08
  7  -0.94 9.226012e-07 6.049380e-08
  8  -0.93 9.542808e-07 7.003660e-08
  9  -0.92 9.898679e-07 7.993528e-08
  10 -0.91 1.028986e-06 9.022514e-08
  ...
  ...
  ...
  </code></pre>
  
  <p>The column <code>Index</code> is a vector, from -1.00 to 10.00.The difference between any consecutive elements is 0.01. It implies that <code>unique(diff(Index))</code> should return only one value and it must be 0.01. However, <code>unique(diff(Index))</code> can return several 0.01.</p>
  
  <p>My purpose is to compute the difference between any two elements of the column<code>CDF</code>, and these two elements are selected by indicating their <code>Index</code>. For example,</p>
  
  <pre><code>a&lt;-DF$CDF[DF$Index==(r+dr)];
  
  b&lt;-DF$CDF[DF$Index==(r-dr)];
  
  res&lt;-a-b;
  </code></pre>
  
  <p><code>r</code> is any number of <code>Index</code>, <code>dr</code>can be 0.01, 0.02 or 0.03. However, since some elements of <code>Index</code> cannot be rounded to 2 digits (although they all look like that), therefore I cannot compute <code>res</code> for any r and dr.</p>
  
  <p>How should I tackle this problem? Thanks for your advice in advance!</p>