You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.20 11:35:45