title: Formatting number in python to bank account format
body: <p>I have tried looking around finding out how to format a number in python to this specific format. Formatting a number to a currency format was pretty easy to figure out but doing this was not.</p>
  <pre><code>&lt;td&gt;{{ &quot;{:,.2f} NOK&quot;.format(acc['AccountBalance']) }}&lt;/td&gt;
  </code></pre>
  <p>So I simply want to format 12345678901 to 1234.56.78901. I want to use this in my flask template website. Every number is always 11 digits, and it should be formatted as 4 digits period 2 digits period 5 digits period.</p>
  <p>EDIT: This is being used in a Flask template, on numbers retrieved from an SQLite table and put into a list. It is the accs['ID'] that is getting this formatting done on it.</p>
  <pre><code>accs = db.execute(
          'SELECT a.ID, ownerID, AccountBalance, AccountName'
          ' FROM atbl_bank_accounts a JOIN atbl_system_users u ON a.ownerID = u.ID'
          ' WHERE a.ownerID = ?',
          (g.user['ID'],)
      ).fetchall()
  </code></pre>
  <p>This again is posted in to a table on the website using flask template as so:</p>
  <pre><code>&lt;table class=&quot;table table-striped table-hover table-borderless mt-5&quot;&gt;
      &lt;thead&gt;
        &lt;tr&gt;
          &lt;th class=&quot;col-2&quot; scope=&quot;col&quot;&gt;Account Number&lt;/th&gt;
          &lt;th class=&quot;col-4&quot; scope=&quot;col&quot;&gt;Account Name&lt;/th&gt;
          &lt;th class=&quot;col-4&quot; scope=&quot;col&quot;&gt;Amount left&lt;/th&gt;
          &lt;th class=&quot;col-2&quot; scope=&quot;col&quot;&gt;Actions&lt;/th&gt;
        &lt;/tr&gt;
      &lt;/thead&gt;
      &lt;tbody&gt;
        {% for acc in accs %}
        &lt;tr&gt;
          &lt;th scope=&quot;row&quot;&gt;{{ acc['ID'] }}&lt;/th&gt;
          &lt;td&gt;{{ acc['AccountName'] }}&lt;/td&gt;
          &lt;!--&lt;td&gt;{{ acc['AccountBalance'] }}&lt;/td&gt;--&gt;
          &lt;td&gt;{{ &quot;{:,.2f} NOK&quot;.format(acc['AccountBalance']) }}&lt;/td&gt;
          &lt;td&gt;
            &lt;button type=&quot;button&quot; class=&quot;btn btn-light&quot; data-toggle=&quot;tooltip&quot; data-placement=&quot;top&quot; title=&quot;Edit name of account&quot;&gt;&lt;i class=&quot;fas fa-edit&quot;&gt;&lt;/i&gt;&lt;/button&gt;
            &lt;button type=&quot;button&quot; class=&quot;btn btn-light&quot; data-toggle=&quot;tooltip&quot; data-placement=&quot;top&quot; title=&quot;Transfer money from account&quot;&gt;&lt;i class=&quot;fas fa-file-invoice-dollar&quot;&gt;&lt;/i&gt;&lt;/button&gt;
            &lt;button type=&quot;button&quot; class=&quot;btn btn-light&quot; data-toggle=&quot;tooltip&quot; data-placement=&quot;top&quot; title=&quot;Delete account&quot;&gt;&lt;i class=&quot;fas fa-trash&quot;&gt;&lt;/i&gt;&lt;/button&gt;
          &lt;/td&gt;
        &lt;/tr&gt;
        {% endfor %}
      &lt;/tbody&gt;
    &lt;/table&gt;
  {% endblock %}
  </code></pre>
  <p>So I either need a solution that works straight in the HTML or in the python script. Apologies for not being clear enough.</p>
  <p>I did search a fair bit around, but if I skipped an article about this I'm sorry.
  Thanks for the answers in advance.</p>