title: Convert a double to fixed decimal point in C++
body: <p>I have a double variable in C++ and want to print it out to the screen as a fixed decimal point number.</p>
  
  <p>Basically I want to know how to write a function that takes a double and a number of decimal places and prints out the number to that number of decimal places, zero padding if necessary.</p>
  
  <p>For example:</p>
  
  <pre><code>convert(1.235, 2)
  </code></pre>
  
  <p>would print out</p>
  
  <pre><code>1.24
  </code></pre>
  
  <p>and</p>
  
  <pre><code> convert(1, 3)
  </code></pre>
  
  <p>would print out</p>
  
  <pre><code>1.000
  </code></pre>
  
  <p>so the function works as</p>
  
  <pre><code>convert(number as double, number of decimal places)
  </code></pre>
  
  <p>and simply prints out the required value to standard output (cout).</p>
  
  <p>Does anyone know how to do this?</p>
  
  <p>Thanks in advance.</p>