AngularJS:货币格式.更改分数大小,千位分隔符和分数分隔符

Gra*_*avy 6 currency internationalization currency-formatting angularjs

我希望在我的网站的特定表格中显示价格小数点后3位.

价格将以英镑,美元和欧元显示.

我的货币过滤器似乎自动将价格四舍五入到小数点后两位.

此外,如果货币是欧元,理想情况下,我想自动将千.位分隔符更改为a 和小数点分隔符为a ,.

angularjs是否支持此功能?

风景

<div ng-controller="SpotController">
    <table class="header-table-spot-prices">
        <thead>
            <tr><th>Spot Prices</th><th>Price</th></tr>
        </thead>
        <tbody>
            <tr ng-repeat="spot in spots">
                <td>{{ spot.item }}</td>

                    <!-- This needs to be 3dp -->
                <td>{{ spot.price | currency:spot.currency }}</td>
            </tr>
        </tbody>
    </table>
</div>
Run Code Online (Sandbox Code Playgroud)

小智 0

这可能与此无关,因为原始帖子是在 2 年前发布的,但是 Angular 的“货币”过滤器接受符号和分数大小作为参数。

例如:

<td>{{ spot.price | currency:spot.currency : 3 }}</td>
Run Code Online (Sandbox Code Playgroud)

将输出您正在寻找的内容,而无需根据货币更改分隔符。您可以创建自己的货币过滤器,首先使用角度过滤器,然后检查条件并更改分隔符。这个笨蛋就说明了这一点。

.filter('myCurrency', ['$filter', function($filter){
      return function(input, symbol, fractionSize){
          input = $filter('currency')(input, symbol, fractionSize);
          if(symbol === '\u20AC'){
            var tempString = "###";
            input = input.replace(",", tempString).replace(".", ",").replace(tempString, ".");
          }
          return input;
      }
    }])
Run Code Online (Sandbox Code Playgroud)

您可能已经根据您的需求解决了这个问题,但将答案放在这里以防其他人遇到类似的问题并看到这篇文章。