![](/img/trans.png)
[英]I wan't to format a string of numbers as a currency in javascript but i don't know how to format my string
[英]HTML table display only two decimal points and format as a currency. (found Javascript function but don't know how to implement)
我试图让我的 html 表格只显示 2 个小数点,并将表格的最后四列格式化为货币。 我在网上找到了这个函数,它是 Javascript,但我不知道如何实现它。 有人可以帮忙吗?
这里有人列出了 Javascript 代码: https ://css-tricks.com/snippets/javascript/format-currency/
这是我的代码:
{% extends "layout.html" %}
{% block main %}
<table style="width:100%" class="table">
<tr>
<th> ID </th>
<th> Username </th>
<th> Stock </th>
<th> Amount </th>
<th> Current Price </th>
<th> Total Value </th>
<th> Current Cash </th>
<th> Grand Total </th>
</tr>
<tr>
<td> {{ user_id }} </td>
<td> {{ username }} </td>
<td> {{ stocks }} </td>
<td> {{ amount }} </td>
<td> {{ price }} </td>
<td> {{ (amount * price) }} </td>
<td> {{ current_cash }} </td>
<td> {{ grand_tot }} </td>
</tr>
</table>
{% endblock %}
很简单,只需使用他提到的同一个函数 CurrencyFormatted,并使用以下代码:
<tr>
<td> {{ user_id }} </td>
<td> {{ username }} </td>
<td> {{ stocks }} </td>
<td> {{ amount }} </td>
<td> {{ CurrencyFormatted(price) }} </td>
<td> {{ CurrencyFormatted(amount * price) }} </td>
<td> {{ CurrencyFormatted(current_cash) }} </td>
<td> {{ CurrencyFormatted(grand_tot) }} </td>
</tr>
您可以在HTML
中使用pipe
来转换正确的currency format:| currency:"INR"
currency format:| currency:"INR"
:
{{ Amount| currency:"INR"}}
输出:
₹100.00
<td>{{item.GradeAVG.toFixed(0)}}</td>
<td>{{item.TarazAVG.toFixed(2)}}</td>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.