-1

How can I write numbers in a cell inside Bootstrap table in accounting format?

For example: one million should be shown as 1,000,000 and not 1000000 (notice commas ',' between digits).

Please note that data data is getting filled by Django app.

Example:

<tbody>
   {% for row in tbl_list %}
       <tr id="port_row_{{row.stock}}_{{index}}">
           {% if row.stock == 'TOTAL'%}
           <td> {{row.stock}}</td>
           {% else %}
           <td> <a target="_blank" style="color:blue;" href="https://www.google.com/finance?q=NSE:{{ row.stock }}">{{row.stock}}</a></td>
           {% endif %}
           <td>{{row.name}}</td>
           <td>{{row.investment_amount}}</td>
           <td>
           {% if row.weekly_gain >= 0 %}
           <div style="color:green">
                +{{row.weekly_gain}}
                <i class="fa fa-arrow-up"></i>
           </div>
           {% else %}
           <div style="color:tomato">
           {{row.weekly_gain}}
           <i class="fa fa-arrow-down"></i>
           </div>
           {% endif %}
           </td>
           <td>{{row.percentage}}</td>
           <td>{{row.percentage_of_portfolio}}</td>
        </tr>
        {% endfor %}
</tbody>
ThinkGeek
  • 4,749
  • 13
  • 44
  • 91
  • please check this stack overflow question. https://stackoverflow.com/questions/16037165/displaying-a-number-in-indian-format-using-javascript – Piyush Jain Sep 16 '19 at 11:20

3 Answers3

0

It depends on where the data is coming from, but you will need to use something like Javascript to do this.

See this question for more information.

JordanGW
  • 174
  • 1
  • 12
0

You can use the javascript accounting.js library:

// Default usage:
accounting.formatMoney(12345678); // $12,345,678.00
Wolfetto
  • 1,030
  • 7
  • 16
0

Since the question was specifically for Django templates, I used django.contrib.humanize when rendering price.

A set of Django template filters useful for adding a “human touch” to data.

To activate these filters, add 'django.contrib.humanize' to your INSTALLED_APPS setting. Once you’ve done that, use {% load humanize %} in a template, and you’ll have access to the following filters.

Documentation

In your code, do <td>{{ row.monday_open_price|intcomma }}</td>

Do not forget to {% load humanize %}
ThinkGeek
  • 4,749
  • 13
  • 44
  • 91