Angular Currency Pipe设置不显示小数失效问题求助
解决Angular Currency Pipe显示整数价格时自动添加.00的问题
哦,我懂你的困扰了!你现在的写法犯了个小错误——把数字格式参数放错了位置,Angular的currency管道参数是有固定顺序的,咱们来修正它:
问题根源
Angular CurrencyPipe的参数顺序是这样的:currency: currencyCode?: string, display?: string | boolean, digitsInfo?: string, locale?: string
你之前直接把'1.0-0'放在了第二个参数的位置,但第二个参数是货币显示模式(比如显示符号、代码,或者布尔值控制是否显示符号),而数字格式是第三个参数,所以之前的设置根本没生效!
修正后的代码
把数字格式参数移到第三个位置就好啦,这里咱们用'symbol'作为第二个参数(显示货币符号,比如$):
<h5 class="price"> <span>{{billingInfo.amount | currency:billingInfo.currencyCode:'symbol':'1.0-0'}}</span> {{billingInfo.period}} </h5>
如果你不想特意指定显示模式,也可以用undefined占位第二个参数,效果是一样的:
<span>{{billingInfo.amount | currency:billingInfo.currencyCode:undefined:'1.0-0'}}</span>
验证结果
修改后,你的输出就会变成:$100 Hour,完美去掉了.00后缀!
内容的提问来源于stack exchange,提问作者Efim Rozovsky
相关产品推荐
相关产品推荐

