我找到了一个示例,它可以将数字限制在2个小数位,并将其转换为货币金额-例如£2.55。
{{ number | currency : 'GBP' : true : '1.2-2'}}
有没有一个简单的管道可以在不应用货币的情况下完成相同的操作?
它有效
.ts -> pi = 3.1415
.html -> {{ pi | number : '1.0-2' }}
Ouput -> 3.14
https://stackblitz.com/edit/angular-e8g2pt?file=src/app/app.component.html
这对我很有效!!!谢谢!!
在Angular 5之后,现在会有所不同:
{{ number | currency :'GBP':'symbol':'1.2-2' }}
{{ orderTotal | number : '1.2-2'}}
//output like this
// public orderTotal = 220.45892221
// {{ orderTotal | number : '1.2-2'}}
// final Output
// 220.45
1.2-2
会出现在Angular 2的数字管道参数中是有帮助的。 https://dev59.com/b1kT5IYBdhLWcg3wh_1U - maudulus{{ x | number : '1.2'}}
也是有效的,并且意思相同。 - Mark E. Haase