title: How to display a double or float on a JPanel to only two decimal places
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/2808535/round-a-double-to-2-significant-figures-after-decimal-point">Round a double to 2 significant figures after decimal point</a>  </p>
  </blockquote>
  
  
  
  <p>I have a problem in which I want to draw a string containing a double or float value up to two decimal value. It is easy to do in using <code>System.out.Printf()</code> but how to so using <code>drawString</code></p>
  
  <p>like the statement below calculates the number to be deawn on JPanel. but what is actually displayed is a String having values upto 14 decimal places. I need to restrict the display to only 2 decimal places</p>
  
  <pre><code>double size= ((int)((((float) maxSize / (float) (40 * 1.0))*100.0))/100.0);
  
  g.drawString("" + size, 135, 100 + range * i);
  </code></pre>