gpt4 book ai didi

javascript - Django 模板 - 会计格式的 Bootstrap 表编号

转载 作者:行者123 更新时间:2023-11-28 16:59:32 25 4
gpt4 key购买 nike

我正在使用 Django 模板在 UI 中填充以下 Bootstrap 表。我希望表中的数字更具可读性(通过在数字之间使用“,”) - 例如:如果数字是一百万,那么它应该显示为 1,000,000 而不是 1000000(注意数字之间的逗号“,”)。

enter image description here

代码

<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.monday_open_price}}</td>

<td>{{row.previous_close}}</td>
<td>
{% if row.price >= row.previous_close %}
<div style="color:green">
{{row.price}}
</div>

{% else %}
<div style="color:red">
{{row.price}}
</div>
{% endif %}
</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>
{% if row.daily_gain >= 0 %}
<div style="color:green">
+{{row.daily_gain}}
<i class="fa fa-arrow-up"></i>
</div>

{% else %}
<div style="color:tomato">
{{row.daily_gain}}
<i class="fa fa-arrow-down"></i>
</div>
{% endif %}
</td>
</tr>

最佳答案

您可以使用django.contrib.humanize呈现您的价格时。

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.

Document

在你的代码中,执行 <td>{{ row.monday_open_price|intcomma }}</td>

别忘了{% load humanize %}

关于javascript - Django 模板 - 会计格式的 Bootstrap 表编号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57962904/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com