【问题标题】:Limit to 2 decimal places with a own pipe使用自己的管道限制为小数点后 2 位
【发布时间】:2021-06-27 06:51:24
【问题描述】:

我找到了一个将数字限制为 2 位小数的示例 {{ 300000|数字:'1.2-2'}}
我得到以下结果 3,000.00。但我想要以下空间为 3 000.00 的结果。 有简单的管道吗?

【问题讨论】:

    标签: angular typescript


    【解决方案1】:

    pipe 中没有为此构建,但您可以创建一个自定义管道,用您喜欢的任何分隔符替换 , 元素

    @Pipe({ name: "stringReplace" })
    class StringReplacePipe {
      transform(val: string, target: string, replaceValue: string) {
        return val.toString().replaceAll(target, replaceValue);
      }
    }
    <h1>{{3000 | number:'1.2-2'| stringReplace:",":" " }}</h1>

    【讨论】:

      猜你喜欢
      • 2016-11-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-04-02
      • 2017-06-07
      • 2021-10-11
      • 1970-01-01
      相关资源
      最近更新 更多