title: Rounding function in C
body: <p>So i am trying to write a code which can allow me to round UP any number to 3 decimal places. My code for rounding up a number was like this :</p>
  
  <pre><code>for (rowIndex = 0; rowIndex &lt; MAX_ROWS; rowIndex++)
  {
      for (columnIndex = 0; columnIndex &lt; MAX_COLUMNS; columnIndex++)
      {
           printf("%.3f ", ceil(rawData[rowIndex][columnIndex] * 1000.0) / 1000.0);
      }
  }
  </code></pre>
  
  <p>But yesterday my teacher told us to use a code which has a structure like this:</p>
  
  <pre><code>float roundValue(float value, int decimalPlaces)
  {
        // Place rounding code here
        return value;
  }
  </code></pre>
  
  <p>i am not quite sure how to write the code in this format! I am a beginner in coding so this might be so silly.</p>
  
  <p>UPDATE:
  so i just read all the comments below and tried to write the code but still has a problem. my code is :</p>
  
  <pre><code>double roundValue(double value, int decimalPlaces)
  {
  value = roundf( value * pow(10, decimalPlaces)) / pow(10, decimalPlaces);
  return value;
  }
  int main(void) 
  {
  int rowIndex = 0;
  int columnIndex = 0;
  double rawData[MAX_ROWS][MAX_COLUMNS]; // 2-dimensional array to store our 
  raw data
  double value = rawData[MAX_ROWS][MAX_COLUMNS];
  int decimalPlaces = 3;
  // Print out the roundup data array
  printf(" --- ROUNDED DATA ---\n");
  for (rowIndex = 0; rowIndex &lt; MAX_ROWS; rowIndex++)
  {
      for (columnIndex = 0; columnIndex &lt; MAX_COLUMNS; columnIndex++)
      {
          printf("%.3f ", roundValue(value, 3));
      }
      printf("\n");
     }
     return 0;
  }
  </code></pre>
  
  <p>it gives me only 0 for all the numbers.</p>