<tutorial title="Formatting Floating Point Values" ht="1">
 <shell lang="java" className="Demo" import="shells.xml#null"/>
 <question className="Demo" title="Printing a decimal values">
  <blurb lang='java'>
  <p>
  The printf method takes a format string as the first parameter.
  This string is printed but the parameters that follow replace the
  % placeholders.
  </p>
  <p>%f is used for floating point values.
  </p>
  <table style='clear:both'>
  <tr>
   <td class='imper'>Format</td>
   <td class='imper' style="width:6em">Code</td>
   <td class='imper'>Meaning</td></tr>
  <tr><td>Simple</td>
   <td><code>%f</code></td><td>The default format</td></tr>
  <tr><td>Fixed decimal places</td>
   <td><code>%.3f</code></td>
   <td>Print three decimal places.</td></tr>
  <tr><td>Right justified</td>
   <td><code>%8.3</code></td><td>Print right aligned in 8 characters.
        Use three decimal places.</td></tr>
  </table>
  </blurb>
  <blurb lang="cs">
  <p>
  The <code>Write</code> method takes a format string as the first parameter.
  This string is printed but following parameters replace the {} placeholders.
  </p>
  <p>In the phrase <code>{0:8:f3}</code> 0 indicates the first parameter
  8 is the number of spaces to use (right justified), f3 means three decimal
  places.</p>
  <table style='clear:both'><tr>
   <td class='imper'>Format</td>
   <td  class='imper' style="width:6em">Code</td>
   <td class='imper'>Meaning</td>
  </tr><tr>
   <td>Simple</td>
   <td><code>{0}</code></td>
   <td>Simple conversion to string</td>
  </tr><tr>
   <td>Three dp</td>
   <td><code>{0:f3}</code></td>
   <td>Three decimal places.</td>
  </tr><tr>
   <td>Right aligned</td>
   <td><code>{0,8:f3}</code></td>
   <td>Print right aligned in 8 characters. Use three decimal places.</td>
   </tr>
  </table>
  </blurb>
<prog lang="cs"><![CDATA[
using System;
public class Demo{
  public static void Main(string[] argv)
  {
    Console.Write("The answer:{0}\n", Math.PI);
    Console.Write("The answer:{0:f3}\n", Math.PI);
    Console.Write("The answer:{0,8:f3}\n", Math.PI);
  }
}
]]></prog>
<prog lang="java">
public class Demo{
  public static void main(String[] argv)
  {
    System.out.printf("The answer:%f\n", Math.PI);
    System.out.printf("The answer:%.3f\n", Math.PI);
    System.out.printf("The answer:%8.3f\n", Math.PI);
  }
}
</prog>

 </question>
</tutorial>

