title: How do I limit the length of a float and not just it's decimals?
body: <p>I'm working on a script that needs to output numbers in a precision determined by length and not just decimal places. Let's say I want a max of 7 decimals but whole numbers above 7 digits are ok although they can't have decimals if the total amount of digits is 7 or higher.</p>
  
  <p>So the rules are:</p>
  
  <pre><code>- If a float has more than 7 digits of whole numbers, it loses it's decimals
  - If a float has less than 7 digits of whole numbers, it gets a length of 7 total digits including decimals
  - If a floats has no digits of whole numbers, it keeps 7 decimals
  </code></pre>
  
  <p>For example:</p>
  
  <pre><code>a = 10000.02
  b = 1.000002
  c = 100000000000
  </code></pre>
  
  <p>are all correct.</p>
  
  <p>How do I handle numbers (all <code>float</code>) in this format?   </p>
  
  <p>For example:</p>
  
  <pre><code>d = 892432589.54680
  e = 382.39810758264057251
  f = 452545871.1643548
  g = 10254.968743541742
  h = 165783438364325.126
  </code></pre>
  
  <p>I was thinking about something along the lines of:</p>
  
  <pre><code>length_of_number = len(str(x))
      if length_of_number &gt; 7:
          x.round(0)
      else:
          x.round(7 - length_of_number)
  </code></pre>
  
  <p>but then I get in trouble with situations like  </p>
  
  <pre><code>x= 0.5313231568943218748
  </code></pre>
  
  <p>because the whole <code>float</code> is longer than 7 digits.</p>
  
  <p>What to do?</p>
  
  <p>Edit for asked examples:</p>
  
  <pre><code>12345678 is ok
  1234567.1 is ok (but 1234567.12 not)
  1.12345678 would become 1.123456
  </code></pre>