Angular 2 CurrencyPipe货币和数字之间的空间? [英] Angular 2 CurrencyPipe space between currency and number?
问题描述
我注意到Angular 2中有一个名为CurrencyPipe的管道,它将从数字中过滤出一些小数.这还会添加ISO货币指标,即"USD"或任何其他本地货币.
I noticed that there is a pipe called CurrencyPipe in Angular 2, which will filter some decimals from a number. This also adds the ISO currency indicator, ie 'USD' or any other local currency.
我的问题是输出显示如下:
My problem is that the output is displayed like this:
USD123
在USD和123之间没有空格的情况下,这真的是首选的做法吗?我是否需要为此编写自己的管道,还是可以做一些添加空格的事情?
Without space between USD and 123, is this really the preferred behavior? Do I have to write my own pipe for this or is there something that I can do to add a space?
这是一些代码:
<span>{{ product.price | currency:'USD' }}</span>
推荐答案
这是不可能的,因为CurrencyPipe
依赖于Intl.NumberFormat
,并且对此没有任何选择.
This isn't possible since the CurrencyPipe
relies on Intl.NumberFormat
and there is no options for this.
也就是说,您可以将symbolDisplay
参数设置为true
来切换为显示$
而不是USD
:
That said you can switch to display $
instead of USD
with the symbolDisplay
parameter set to true
:
<span>{{ product.price | currency:'USD':true }}</span>
这将显示:$123
更好;-)如果这不适合您,则需要实现一个自定义管道来格式化您的电话号码...
This will display: $123
which is a bit better ;-) If this doesn't suit you, you need to implement a custom pipe to format your number...
有关更多详细信息,请参见以下链接:
See these links for more details:
- https://github.com. com/angular/angular/blob/master/modules/angular2/src/facade/intl.ts#L70
- https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/NumberFormat
- https://github.com/angular/angular/blob/master/modules/angular2/src/facade/intl.ts#L70
- https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/NumberFormat
这篇关于Angular 2 CurrencyPipe货币和数字之间的空间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!