【问题标题】:Showing price 2 decimal places with comma angular7 / ionic4用逗号 angular 7 / ionic 4 显示价格 2 位小数
【发布时间】:2019-04-30 20:37:04
【问题描述】:

您好,我从 api 返回价格,例如 1.00 或 2.00,但在模板中我想将其显示为 €1,00 或 €2,00。我正在做以下事情:

<ion-icon name="pricetag" color="secondary"></ion-icon> Minimale Kbestelling <B>{{item.minimal_order | currency:'EUR'}}</B>

如何替换 .逗号?我知道千位分隔符使用逗号,但我只想显示逗号我该怎么做?

我没有看到这样做的选项: https://angular.io/api/common/CurrencyPipe

【问题讨论】:

    标签: angular7 currency


    【解决方案1】:

    Angular 国际化页面 (https://angular.io/guide/i18n) 提供了大量有关本地化应用程序的信息。如果您想使用逗号基数而不是小数点,您可以选择适当的语言环境,然后将其作为您的货币管道配置的参数。

    currency 管道的第四个参数是用于显示的语言环境,它决定使用逗号还是句点作为基数符号。例如,fr 语言环境可能如下所示:

    https://codesandbox.io/s/k203o9nr07

    import { Component } from "@angular/core";
    import { registerLocaleData } from "@angular/common";
    import localeFr from "@angular/common/locales/fr";
    
    registerLocaleData(localeFr, "fr");
    
    @Component({
      selector: "app-root",
      template: "<div>My number is {{this.value | currency:'EUR':'symbol':'':'fr'}}</div>"
    })
    export class AppComponent {
      value = 1234.5678;
    }
    

    来源:

    【讨论】:

    • 是的,我输入了荷兰语并做到了 | currency:"EUR":'€':"1.2":'nl' 现在可以使用了
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-02-07
    • 1970-01-01
    • 1970-01-01
    • 2015-10-08
    • 1970-01-01
    • 2015-03-25
    相关资源
    最近更新 更多