title: Python print a float with a given number of digits
body: <p>I have some floating point values in Python. I would like to print them so that the have the same number of digits (sum of the integer and decimal parts)</p>
  
  <p>For example considering the two numbers:</p>
  
  <pre><code>a = 12.123456
  b = 123.1234567
  </code></pre>
  
  <p>I would like to print their value formatted as follows:</p>
  
  <pre><code>12.1234
  123.123
  </code></pre>
  
  <p>So that they have the same length.</p>
  
  <p>One simple way is the following:</p>
  
  <pre><code>if (val&gt;100):
      print("%0.3f" % val)
  else:
      print("%0.4f" % val)
  </code></pre>
  
  <p>Is there a smarter way to control both the number of integer and decimal digits at the same time in python so that the resulting string is constant?</p>