title: Writing formatted text in SWI-Prolog
body: <p>I have spent a significant amount of time in the SWI-Prolog documentation and am getting nowhere.  My desire is to be able to format numbers that are output such that I am controlling total # decimal digits displayed and also right aligning the numbers in a given character width.  For example:</p>
  
  <pre><code>  2.500   (trailing zeroes displayed)
   34.432   (rounded from a much longer decimal value)
  213.110
  </code></pre>
  
  <p>All 3 are right aligned in a 7 character wide space, with 3 decimal places displayed (even when those are zero).  I can accomplish some of these things individually, but not all at once.</p>
  
  <pre><code>writef( '%7R', [34.342]).
  writef( '%7R', [34.300]).
  </code></pre>
  
  <p>^^^ This comes very close to what I want, but unfortunately it does display any trailing zeroes (it will always omit them).  Also, I have to do the rounding manually before passing the rounded value to writef().</p>
  
  <pre><code>format( '~3f', 34.34219089).
  format( '~3f', 1234.3).
  </code></pre>
  
  <p>This one does the rounding, and allows trailing zeroes, but I can find no way to force right alignment using the "format" function, and I can't find a way to combine the functionality of writef (alignment) with format (rounding and zero display).</p>
  
  <p>Any ideas?</p>
  
  <p>Thanks much!</p>