title: In octave, how to print a number up to d decimal places, where d is a value that the user inputs
body: <p>I want to print a variable <code>val</code> up to <code>d</code> decimal places, where <code>d</code> is input by the user. The value of <code>d</code> is not known while writing the program. </p>
  
  <p>I tried the following:</p>
  
  <pre><code>printf ('%.df',val);
  printf ('%.{%i}f',d,val);
  </code></pre>
  
  <p>It doen't seem to work though.</p>